【发布时间】:2012-03-27 11:57:51
【问题描述】:
所以我做了一个非常简单的程序,从 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
【问题讨论】:
-
考虑:
for bottles in range(lim, 0, -1): .... -
您使用的是 Python 2 还是 3?因为在 Python 3 中使用了
input()和print()函数,但是您的第一行脚本显示为:#!/usr/bin/env python而不是#!/usr/bin/env python3。你能指定你想运行哪一个吗?
标签: python math numbers integer