-1
   nombre=str
    while nombre==str:
     try:
      nombre=int(input("give an integer"))
     except ValueError:
      print("give a number")
      nombre=int(input("give an integer"))
splash58
  • 26,043
  • 3
  • 22
  • 34
MEMER
  • 23
  • 5

1 Answers1

0
  • Setting nombre = str doesn't seem right, because str is a type and the idea is for nombre to eventually be an instance of an actual number.
  • You don't need to repeat yourself inside the loop, as long as the failure results in the while condition remaining true.

I think this will work:

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
Samwise
  • 68,105
  • 3
  • 30
  • 44