我正试图为Yahtzee游戏制作一个记分员,但每当我为players
输入变量时,它总是打印"I think that's enough."
。请帮助我了解这里发生了什么以及如何修复它。
#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."
raw_input
生成一个字符串,并将其与一个数字进行比较。在Python 2中,结果如您所见。尝试以下操作:
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!"