So far we have worked with input() textual values (strings). But what if we want to interact with numbers instead of text? Indeed input() ”reads” text from the input, so Python needs to know if we would like to treat the inputted text as a number. That can be accomplished with int():
# Sample input:
Hi, my age and height are:
24
180
# Sample output:
The text was: Hi, my age and height are:
24 180 204
int stands for integer (whole number). int(...) converts the inputted text to an integer. So, when the user inputs 20, it is converted to a number 20 and then can be used for addition, multiplication, etc.
If the user inputs a wrong value, let's say hello instead of a number num1 (24 in the example above), Python would try to convert it to int and would result in an error telling that it wasn’t able to do so ValueError: invalid literal for int() with base 10: 'hello'. ValueError indicates that there was a wrong value provided and the program is not able to treat the input as a number.
Challenge
Write a program that inputs a number n and prints The number you have entered is: and its value.