Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我试图创建一个循环,如果输入不是带有exept VALUERROR的int,则会触发该循环 设置nombre=str似乎不正确,因为str是一种类型,其思想是让nombre最终成为实际数字的一个实例 您不需要在循环中重复自己的操作,只要故障导致,而条件保持为真_Python - Fatal编程技术网

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
without
mypy
只是我的
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