我的Python程序不起作用,它需要几天才能完成,我需要让它运行起来。问题是你想再次参加。这是:
n1 = input ("How many bottles would you like?\n")
n = int (n1)
playing = True
while playing:
while n > 1:
print (n," green bottles sitting on a wall,")
print (" ")
print (n," green bottles sitting on a wall,")
print (" ")
print ("And if one green bottle should accidently fall,")
print (" ")
print ("There would be ", n-1," green bottles sitting on a wall")
print (" ")
n = n - 1
print ("1 green bottle, sitting on a wall,")
print (" ")
print ("1 green bottle, sitting on a wall,")
print (" ")
print ("And if one green bottle should accidently fall,")
print (" ")
print ("There would be no green bottles sitting on a wall")
again = input ("Would you like to go again?")
if again == "yes" or "Yes":
n1 = input ("How many bottles would you like then?")
n = int (n1)
if again == "no" or "No":
playing = False
问题在于,当它问我是否想再去时,它会说"那么你想要多少瓶?"即使我把"没有"作为答案。我想知道如何修复它,以便当我进入" no"我也想知道它是如何完成的。
答案 0 :(得分:0)
问题在于:
if again == "yes" or "Yes":
这应该改为
if again == "yes" or again == "Yes":
会发生什么? Python首先评估again == "yes"
,然后仅评估术语"Yes"
。后者将始终为true
,因为其值不是0
(因此,Python自动true
同样适用于
if again == "no" or "No":
始终将评估为true
。