-2

I am trying to make a scorekeeper for a game of Yahtzee but whenever I put in a variable for players it always prints "I think that's enough." Please help me understand what is happening here and how I could fix it.

#Yahtzee Scorekeeper

if __name__ == "__main__":

    players = raw_input("How many people will be playing?")

    if players == 1:
        print "You can't play Yahtzee by yourself!"
    elif players == 2:
        print "Ready to start with " + str(players) + " players!"
    elif players == 3:
        print "Ready to start with " + str(players) + " players!"
    elif players == 4:
        print "Ready to start with " + str(players) + " players!"
    elif players == 5:
        print "Ready to start with " + str(players) + " players!"
    elif players == 6:
        print "Ready to start with " + str(players) + " players!"
    elif players == 7:
        print "Ready to start with " + str(players) + " players!"
    elif players == 8:
        print "Ready to start with " + str(players) + " players!"
    elif players > 8:
        print "I think that's enough."
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • Note also that your code is very repetitive; the code for cases 2-7 is identical, so could be trivially simplified. – jonrsharpe Apr 05 '15 at 22:23

1 Answers1

1

raw_input produces a string, and you're comparing it with a number. In Python 2, the result is as you saw. Try the following:

players = int(raw_input("How many people will be playing?"))

if players < 2:
    print "You can't play Yahtzee by yourself!"
elif players > 8:
     print "I think that's enough."
else:
    print "Ready to start with " + str(players) " players!"
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97