我试图添加用户输入的值,在输入q
退出后显示总数。我想在退出程序之前显示该值,但我总是遇到此错误
Exception has occurred: Value Error invalid literal for integer () with base 10: 'q'"
while True:
seatvalue = int(input("please enter seat value (eg.30), 'q' to quit "))
if seatvalue == 'q':
print [(seatvalue) + (seatvalue)]
print ("bye")
break
问题是:
该行尝试将“q”转换为int,只需在转换为int之前检查是否为int,就可以通过“isnumeric”函数实现这一点
请注意,此代码将省略所有不是数字或“q”的内容
相关问题 更多 >
编程相关推荐