我有一个非常简单的try / except块,基本上可以将变量“ password”从用户输入中定义为整数。
这可能是一个愚蠢的问题,但是我尝试环顾四周,却找不到解决方案。
Blob
但是,当我尝试运行此python shell时,它出现了一个语法错误,突出显示了'except'...
答案 0 :(得分:0)
在password = ...
之后删除新行。壳牌希望除外块而不是新行。另外,您的括号也不完整。
try:
password = int(input('Bob should have issued you with your 4-digit numerical password, please enter it here: '))
except ValueError:
print("Please do not type letters or symbols!!")
答案 1 :(得分:0)
有几个问题:
password=""
try:
password = int(input('Bob should have issued you with your 4-digit numerical password, please enter it here: '))
except ValueError:
print("Please do not type letters or symbols!!")
while type(password) is not int:
try:
password = int(input('Bob should have issued you with your 4-digit numerical password, please enter it here: '))
except ValueError:
print("Please do not type letters or symbols!!")
print('Complete, we have your password.')