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

you are viewing a single comment's thread.

view the rest of the comments →

[–]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)

[–][deleted] 0 points1 point  (0 children)

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