我正在尝试为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."
答案 0 :(得分:1)
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!"