[I edited the question since it has been closed.]
Asked
Active
Viewed 49 times
-5
-
`age = int(input('How old are you: '))` – Johnny Mopp Jan 12 '21 at 13:46
-
5Does this answer your question? [How to convert strings into integers in Python?](https://stackoverflow.com/questions/642154/how-to-convert-strings-into-integers-in-python) – Countour-Integral Jan 12 '21 at 13:47
2 Answers
0
To do so you can use int(age). You may want to implement a try/catch so that the program doesn't throw an exception when the input is invalid.
D4v1d 247
- 1
- 2
- 3
-
1It's not a crash, it's an exception that is thrown, with traceback telling your what went wrong, and then the "program" is terminated. A crash (e.g a segmentation fault) would end the script without any details. – Countour-Integral Jan 12 '21 at 13:51
0
Hey in Python input() is by default store string type value. So you have to put
age=int(input('How old are you: '))
Here int() will store integer type value.
OR
you can also do int(age)
Ujjwal Dash
- 602
- 1
- 2
- 8