Beginner · PYTHON PROGRAMMINGInput and type conversion
What you will learn
Read standard input, trim text and convert numeric data.
Understand the concept
input() always returns a string. Convert it with int only when numeric input is expected.
Practise
Handle an invalid age using try and except ValueError.
[py_tutorial_code]
Experiment with the program below. Your code and input are sent to the selected compiler only when you run it.
Tab indents · Shift+Tab unindents · Esc then Tab leaves the editor · Ctrl/Cmd+Enter runs · Ctrl/Cmd+S saves a draft
Changes save automatically to your account.
Input / output example
Example inputRavi
20
Expected output for the original programRavi will be 21
Output will appear here.
Log in to save your progress