所以我做了一个非常简单的程序,从99(唱99瓶啤酒)开始倒计时,但是我总是得到2个错误中的1个
#!/usr/bin/env python
print("This program sings the song 99 bottles of beer on the wall")
lim = input("What number do you want it to count down from?")
def sing():
global lim
while int(lim) >= 0:
if int(lim) != 1 or int(lim) != 0:
print(lim, "bottles of beer on the wall", lim, "bottles of beer")
print("Take one down pass it around...")
print(lim, "bottles of beer on the wall")
input("\nPRESS ENTER\n")
lim -= 1
sing()
TypeError: unsupported operand type(s) for -=: 'str' and 'int'
然后,当我将
lim -= 1
更改为int(lim) -= 1
时,它会显示SyntaxError: illegal expression for augmented assignment
最佳答案
你需要把lim从字符串转换成整数。试试这个:
lim = int(input("What number do you want it to count down from?"))