【发布时间】:2021-03-18 14:50:43
【问题描述】:
我想这样做,但我评论了 3 个问题:
age = input("How old are you ? ")
if type(age) != int: # this line does't work
restart = input("invalid input. Do you want to restart ? [y/n]")
if restart == "y" :
#restart the program
else :
#exit the program
【问题讨论】:
-
input返回一个str,即使该字符串恰好代表一个数字。 -
所以你说我不应该首先使用输入来获取年龄?那我该怎么办?
标签: python input exit restart invalid-characters