【发布时间】:2016-03-21 16:24:22
【问题描述】:
您好我是编码新手,这里我根据用户的输入编写了一个简单的代码。我可以得到每个 if 和 elif 响应,但是当输入不是整数时,我的程序会失败。
def tables_bussed():
tables = input("How many tables can you bus per hour? (I can only read numbers.)")
if int(tables) > 80:
print ("That\'s rediculous, you lying twit.")
tables_bussed()
elif int(tables) > 60:
print ("If what you are saying is true then you have quite a talent!")
elif int(tables) > 30:
print ("Impressive! Yet there\'s always room for improvement, now isn\'t there.")
elif int(tables) > 0:
print ("How sad.")
else:
print ("Are you dumb or just daft.")
tables_bussed()
tables_bussed()
我的 else 子句中是否遗漏了什么?
【问题讨论】:
-
您得到的确切错误是什么?您的最终打印没有缩进,但我认为这只是复制粘贴问题?
-
缺少缩进
-
else 语句中的缩进似乎不正确。
-
错误信息的最后一行是 ValueError: invalid literal for int() with base 10: ''
-
请编辑您的缩进以与您的代码完全匹配。我认为这对
Python语言很重要
标签: python