So far we have seen that the function
input treats what you
type as a string of characters. But sometimes it is useful to have
Python interpret the characters as Python constants. For example,
when you input your age, we saw that the result was treated as a
string of characters. To get Python to treat it as an integer
constant, you would do this:
evalfunction interprets the character string and determines its type automatically. So if you enter the number 25, the
evalfunction converts it to an integer, assigns it to the variable
int. Then you can do arithmetic with it without further conversion.
The order of operations in this example is found by reading from
inside-to outside the parentheses and from right to left. First, the
input function reads a string of characters from the keyboard,
eval function operates on that string, and, finally,
the result is stored in the variable
If you use the same procedure to enter your name, as in
namebecomes a string variable.
Try changing your code so both your name and age are read using the
eval function to process the result of the
function. Then see what happens if you print your age in five years
by simply using addition as in
age + 5.