Python 我试图创建一个循环,如果输入不是带有exept VALUERROR的int,则会触发该循环 设置nombre=str似乎不正确,因为str是一种类型,其思想是让nombre最终成为实际数字的一个实例 您不需要在循环中重复自己的操作,只要故障导致,而条件保持为真
我认为这会奏效:Python 我试图创建一个循环,如果输入不是带有exept VALUERROR的int,则会触发该循环 设置nombre=str似乎不正确,因为str是一种类型,其思想是让nombre最终成为实际数字的一个实例 您不需要在循环中重复自己的操作,只要故障导致,而条件保持为真,python,Python,我认为这会奏效: nombre=str while nombre==str: try: nombre=int(input("give an integer")) except ValueError: print("give a number") nombre=int(input("give an integer")) 在这里输入似乎有点过火,同意不同意pythonwithoutmypy只是我的thon。 from typin
nombre=str
while nombre==str:
try:
nombre=int(input("give an integer"))
except ValueError:
print("give a number")
nombre=int(input("give an integer"))
在这里输入
似乎有点过火,同意不同意python
withoutmypy
只是我的thon
。
from typing import Optional
nombre: Optional[int] = None
while nombre is None:
try:
nombre=int(input("give an integer"))
except ValueError:
print("that's not a valid integer, try again?")
assert nombre is not None