Skip to content
Sign upLog in
← Back to Community

Ask Age

Profile icon
CassioTDS

I Need To Ask The Player Age But He Only can put numbers.

Voters
Profile icon
NoahMB1
Profile icon
ArashHabibi
Profile icon
CassioTDS
Comments
hotnewtop
Profile icon
ash15khng

You could use
age = int(input("what is your age?"))
This stores the input as a variable age.
If the player types in a non number, there will be an error.

Profile icon
Four_Of_Clubs

@ash15khng
Is there any way to test for it without creating an error? I've tried the type() function, but it doesn't seem to work.

Profile icon
ash15khng

@Four_Of_Clubs There is no type() function in Python if I'm not wrong.
You could use a try except loop, something like this:

try: age = int(input("what is your age?")) except ValueError: print("invalid number")
Profile icon
Four_Of_Clubs

@ash15khng
Thanks!

Profile icon
ash15khng

@Four_Of_Clubs No problem!

Profile icon
CassioTDS

Guys! I Figured It Out! A Coder Teaches Lessons To My Dad Andash15khng was right just that it is exept: Not Exept ValueError: (actually idk)