0
while True:
    age = int(input("*--How old are you?: "))

    if age < 18:
        print("Better go home!")
    elif age != int:
        print ("Use some numbers dude")

I tried some hours I searched but I don't understand it I just found the .isdigit()

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91

1 Answers1

0

If the user inputs some non-digit string then the conversion to int() fails and ValueError is thrown.

You can handle this exception in try...except block. For example:

while True:
    try:
        age = int(input("*--How old are you?: "))
    except ValueError:
        print("Use some numbers dude")
        continue

    if age < 18:
        print("Better go home!")
    else:
        print("OK")

    break

Prints:

*--How old are you?: twentyone
Use some numbers dude
*--How old are you?: 21
OK
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91