0

I get that there isnt enough arguments to format string, any suggestions? It is in the else f.write line (52). This is taking the average pixel value and replacing it with a second image. As you can see the file reads both images and writes them. During the write process I get an error saying that there isn't enough arguments to format the string.

def main():
f = open("BoardHappy.ppm","r")
lines = f.readlines()
kinds = lines[0]
size=lines[1].split()
width=int(size[0])
height=int(size[1])
depth = int(lines[2])

red=[]
green=[]
blue=[]
for i in range(3, len(lines)):
    temp = lines[i].split()
    for j in range(0, len(temp) ,3):
        red.append(int(temp[j]))
        green.append(int(temp[j+1]))
        blue.append(int(temp[j+2]))
f.close()

f = open("Godzilla.ppm","r")
lines = f.readlines()
kinds = lines[0]
size=lines[1].split()
width=int(size[0])
height=int(size[1])
depth = int(lines[2])

red1=[]
green1=[]
blue1=[]
for i in range(3, len(lines)):
    temp = lines[i].split()
    for j in range(0, len(temp), 3):
        red1.append(int(temp[j]))
        green1.append(int(temp[j+1]))
        blue1.append(int(temp[j+2]))
f.close()


f = open("lab5.ppm","w")
f.write("P3 \n")
width=720
height=540
f.write("%d %d \n"%(width,height))
f.write("255 \n")
for i in range(width*height):
    new = (red[i]+green[i]+blue[i])/3.0
    if new >=100:
        f.write("%d %d %d/n"% red[i], green[i],blue[i])
    else:
        f.write("%d %d %d/n"% red1[i], green1[i], blue1[i])

f.close()

main()

1 Answer 1

1

You need brackets:

f.write("%d %d %d/n"% (red[i], green[i],blue[i]))
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I feel dumb. Thank you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.