-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
  • 25,715
  • 3
  • 20
  • 32
MEMER
  • 21
  • 4

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
  • 51,883
  • 3
  • 26
  • 36