Ask coding questions

← Back to all posts
How to input numbers
CodeQueen4123

Since you guys are better than me do you mind telling me how to put a code for when I put in a command for it only to accept numbers

Answered by Highwayman [earned 5 cycles]
View Answer
Voters
DhanvineR
CodeQueen4123
Comments
hotnewtop
Highwayman

You can surround a casted input statement with a try - except block and a loop that just does another input if the cast fails.

CodeQueen4123

@Highwayman
Thank you I will try that

Highwayman
CodeQueen4123

@Highwayman
Hey I had to run an errand do you mind showing me what it should look like hope u r still on

CodeQueen4123

@Highwayman
Nvm I found out 🙏🏾 for ur help tho

Muffinlavania

You can als do this:

Of course you can loop it and stuff but that is the foundation

thenullified
CodeQueen4123

Because it doesn’t say error when I don’t put numbers