Ask coding questions

← Back to all posts
Ask Age
CassioTDS

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

Voters
ArashHabibi
CassioTDS
Comments
hotnewtop
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.

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.

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:

Four_Of_Clubs

@ash15khng Thanks!

ash15khng

@Four_Of_Clubs No problem!

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)