【发布时间】:2017-10-12 23:10:13
【问题描述】:
try:
user_name = str(input("Enter your full name: "))
except:
print("Enter a string")
user_age = int(input("Enter your age: "))
user_country = str(input("Enter the country you live in: "))
user_postcode = str(input("Enter your postcode: "))
当我为第一个输入一个整数时,它会移动到下一个变量,但我希望它说“输入一个字符串”
【问题讨论】:
-
输入已经返回一个字符串
-
读成
try <this> and continue except when it screws up with <exception> do this instead可能会有所帮助。由于块中的所有内容都是字符串,因此它永远不会搞砸。
标签: python try-except