当输入任何非数字的内容时,我不断收到ValueError:int()的无效字面量(以10为底):'no'。我想得到的是“无效输入:仅输入大于0的整数。”
while True:
if tax_str in ['s', 'm']:
income_str = int(input("Please enter your income rounded up to the\
nearest whole number: ")) # I am not sure what the problem is here
status = 'single' or 'married'
income_str = int(income_str)
income = income_str
whole_positive = income_str.isdigit()
while not whole_positive:
print("INVALID INPUT: input only whole number greater than 0.")
print()
income_str = input("Please enter your income rounded up to the nearest \
whole number: ")
whole_positive = income_str.isdigit()
这是测试运行。我不确定如何解决此问题。
Are you filing single or married?
(Type 's' or 'm' or <ENTER> to quit): m
Please enter your income rounded up to the nearest whole number: hi
Traceback (most recent call last):
File "C:\Users\Jay Kim\Desktop\Part1.py", line 123, in <module>
main()
File "C:\Users\Jay Kim\Desktop\Part1.py", line 66, in main
nearest whole number: "))
ValueError: invalid literal for int() with base 10: 'hi'
答案 0 :(得分:0)
您输入的是“ hi”,但应为整数,因此会出现此错误。
放置此行income_str = int(input("Please enter your income rounded up to the..))
除尝试之间