0

The methods that I have used up until this point have involved try/except, if statements and while loops, but they have not given the desired result. They either keep on allowing strings or producing an exception or not allowing any entry.

Age2 = input('Age (Numbers Only):') #3
while type(Age2)!=type(1):
    print('\nPlease define Age in numbers only\n')
    Age2 = input('Age (Numbers Only):')

I am also uncertain how to add a limit that prohibits the user from entering the age: 0 into the system.

Brent
  • 177
  • 2
  • 9

1 Answers1

2

You need to check whether age2 is an instance of int. :

age2 = input('Age (Numbers Only):')
while not all([age2 > 0, isinstance(age2 , int)]):
    print('\nPlease define Age in numbers only\n')
    age2 = input('Age (Numbers Only):')
Bahrom
  • 4,752
  • 32
  • 41