Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
3

Ask Age

CassioTDS
CassioTDS

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

4 years ago

Voters

Comments

TopNew
2
ash15khng
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.

4 years ago
1
Four_Of_Clubs
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.

4 years ago
3
ash15khng
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")
4 years ago
2
ash15khng
ash15khng

@Four_Of_Clubs No problem!

4 years ago
1
CassioTDS
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)

4 years ago
Load more