Collect user data, convert it, and build interactive programs.
This program always welcomes the same person.
How could we let a different person enter their own name each time?
input() replaces a fixed value with data from the user.
Plan what enters, what changes, and what leaves.
I
Input
Data the program receives.
P
Processing
Conversion or calculation performed on the data.
O
Output
Information the program displays.
Every part of the plan has a visible job in the program.
Typing digits does not automatically create a number.
Read the call from the prompt to the stored value.
name = input("What is your name? ")
What exact type is printed?
What happens when this program runs?
Turn integer text into a number before calculating.
Read nested calls from the inside out.
The final value stored in age is an int.
What value is printed?
Use float() when valid input may contain a decimal point.
Match the conversion to the meaning of the data.
Whole Count
Age, quantity, number of tickets
Decimal Measurement
Price, distance, temperature
Keep as Text
Name, color, message
What value is printed?
Conversion only works when the text matches the requested number type.
For now, follow the prompt and enter valid data.We will handle invalid input later.
Tell the user what value to enter and include the unit.
What?
Name the value: distance or time.
Which Unit?
Include km, hours, yuan, or another unit.
Input becomes numeric data, processing creates a result, and output explains it.
Complete it on time and submit it before the deadline.
Key takeaways from this lesson.
Input
input(prompt) waits for one line of user text.
Text First
The value returned by input() is always a str.
Convert
Use int() for whole numbers and float() for decimals.
Plan with IPO
Identify input, processing, and output before building.
Find the three jobs inside a complete program.
1. Create a new Python file and enter the example code.
2. Add comments that label the Input, Processing, and Output lines.
3. Run the program with the example input and confirm the output.
Name: Kai Hours studied: 1.5 Kai studied for 90.0 minutes.
Collect text and use it in one clear sentence.
1. Ask for the user's name.
2. Ask for a programming project they would like to build.
3. Print one complete sentence using both values in an f-string.
4. Run the program twice with different answers.
What is your name? Mina What would you like to build? a robot controller Mina wants to build a robot controller.
Convert integer text before adding one.
1. Ask for the user's name and current age.
2. Convert the age with int().
3. Calculate the age next year.
4. Print the result in a complete f-string sentence.
Ava 14
Ava will be 15 next year.
Plan the IPO, choose two conversions, and calculate a total.
1. Write three comments that describe the program's Input, Processing, and Output.
2. Ask for an item name, unit price, and quantity.
3. Convert the price with float() and quantity with int().
4. Calculate and print a clear receipt with an f-string.
Notebook 12.5 3
3 x Notebook costs 37.5 yuan.
Translate a formula into an interactive Python program.
1. Ask for a Celsius temperature and convert it with float().
2. Translate the formula below into a Python expression.
3. Print both temperatures with an f-string.
4. Test the program with 0 and 100.
Celsius temperature: 0 0.0ยฐC = 32.0ยฐF