python - I can't understand why my else statement wont be called -


for practice built basic voting program, can't understand why "else" statement never gets called?

import random  vote = input("please submit vote canda, candb or choose third party: \n")  canda = "person1" candb = "person2" other = "a third party candidate"  if canda:     print("thankyou! vote submitted!") elif candb:     print("thankyou! vote submitted!") elif other:     print("thankyou! vote submitted!") else:     print("you did not submit vote!")  total_votes = random.choice([canda, candb, other]) amount = random.randint(1, 10)  print(total_votes + " won election " + str(amount) + " votes!") 

thank in advance

if variable different none or '' considered true. when call `if canda" , canda contains string"person1" wich result in true. can try like:

if vote == canda:     etc elif vote == candb:     etc elif vote == candc:     etc else:     etc 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -