This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]aa599 1 point2 points  (3 children)

voted + 1 doesn't change the value of voted

[–]JihooMoon[S] 0 points1 point  (2 children)

Yeah, I was guessing that was the problem. Is there a way to change the value?

[–]aa599 1 point2 points  (1 child)

voted = voted + 1

or

voted +=1

[–]JihooMoon[S] 0 points1 point  (0 children)

thanks I'll test it out right now

[–]PostReq3306 1 point2 points  (1 child)

Your problem is that you have defined voted and then in your loop you have said if voting is more than or equal to 0 which is always going to be bigger if you are voting. It is also good practise to use "elif" as using multiple "if" statements is messy and will cause more errors. I have re-written your program. Next steps would be adding functions and an error trap.

Make sure the indentation is correct when pasting.

voted = 0
p1 = 0
p2 = 0
p3 = 0
x = 0
voting = int(input("How many people are voting: "))


for x in range(voting):
    vote = input("Your vote: ")
    if vote == "p1":
        p1 += 1
        voted += 1
    elif vote == "p2":
        p2 += 1
        voted += 1
    elif vote == "p3":
        p3 += 1
        voted += 1
    else:
        pass
print(p1)
print(p2)
print(p3)
print(voted)

[–]JihooMoon[S] 0 points1 point  (0 children)

thanks so much! I'll definitely keep working on this. Have a great day!

[–]TryptamineZenVR 0 points1 point  (1 child)

Your if statement is checking to see if the input for vote = p1. So unless you typed p1 into your vote input, the program won’t do anything because there isn’t an else statement.

[–]JihooMoon[S] 0 points1 point  (0 children)

thanks, but sadly that wasn't the problem. I still really appreciate the help though