Go to Chapter 23 in A Smarter Way.
You can ask for user input and put it into a variable in one line:
user_age = input("Enter your age: ") print(user_age)
Anything the user enters will be treated as a string. Sometimes that’s a problem, since you may need to do math with their input.
age_integer = int(user_age)
To convert the string to a decimal value (a float):
age_float = float(user_age)
If you need to convert a number back into a string:
age_float = str(age_float)
- Create a new code block in your examples.py file.
- Request the user’s name and age (in other words make two requests).
- Format the inputs properly to print them in a line that contains the user’s name followed by their age.