Unit 1 ยท Lesson 5

Input, Conversion & IPO

Collect user data, convert it, and build interactive programs.

๐Ÿ“Œ A Fixed Name

This program always welcomes the same person.

fixed_name.py

How could we let a different person enter their own name each time?

๐ŸŽ›๏ธ Let the User Choose

input() replaces a fixed value with data from the user.

user_name.py

๐Ÿ”„ The IPO Model

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.

๐Ÿงพ IPO in Real Code

Every part of the plan has a visible job in the program.

order_total.py
1

Input

Read the user's name.
2

Processing

Build the welcome message.
3

Output

Print the message.

โŒจ๏ธ input() Returns Text

Typing digits does not automatically create a number.

inspect_input.py
Console Output
14 <class 'str'>

๐Ÿงญ How input() Works

Read the call from the prompt to the stored value.

1

Show the Prompt

Python displays the text inside input(...).
2

Wait

The program pauses until the user presses Enter.
3

Return Text

The typed line returns as a str and can be stored.

name = input("What is your name? ")

๐Ÿ” Input Type Check

What exact type is printed?

input_type.py

๐Ÿ” Text Cannot Add a Number

What happens when this program runs?

broken_age.py

๐Ÿ”ข Convert with int()

Turn integer text into a number before calculating.

next_year.py
Console Output
Next year: 15

๐Ÿ”— Combine Input and Conversion

Read nested calls from the inside out.

combined_input.py
1

Input Runs First

input() returns text such as "14".
2

Conversion Runs Next

int() converts that text into 14.

The final value stored in age is an int.

๐Ÿ” Integer Conversion Check

What value is printed?

integer_check.py

๐Ÿ’ง Convert with float()

Use float() when valid input may contain a decimal point.

price_total.py
Console Output
Total: 37.5 yuan

๐Ÿงฉ Choose the Conversion

Match the conversion to the meaning of the data.

int

Whole Count

Age, quantity, number of tickets

float

Decimal Measurement

Price, distance, temperature

str

Keep as Text

Name, color, message

๐Ÿ” Conversion Check

What value is printed?

conversion_check.py

โš ๏ธ When Conversion Fails

Conversion only works when the text matches the requested number type.

ticket_input.py

For now, follow the prompt and enter valid data.We will handle invalid input later.

๐Ÿ’ฌ Write a Useful Prompt

Tell the user what value to enter and include the unit.

speed_inputs.py
?

What?

Name the value: distance or time.

km

Which Unit?

Include km, hours, yuan, or another unit.

๐Ÿงพ A Complete IPO Program

Input becomes numeric data, processing creates a result, and output explains it.

receipt.py
Console Output
3 x Notebook Total: 37.5

๐Ÿ“ Homework

Complete it on time and submit it before the deadline.

๐Ÿ”– Summary

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.

๐Ÿท๏ธ Task 1: Label the IPO

Find the three jobs inside a complete program.

Your Goal

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.

Example Code
Example Output
Name: Kai
Hours studied: 1.5
Kai studied for 90.0 minutes.

๐Ÿ‘‹ Task 2: Personal Greeting

Collect text and use it in one clear sentence.

Your Goal

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.

Example Output
What is your name? Mina
What would you like to build? a robot controller
Mina wants to build a robot controller.

๐ŸŽ‚ Task 3: Next Birthday

Convert integer text before adding one.

Your Goal

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.

Example Input
Ava
14
Example Output
Ava will be 15 next year.

๐Ÿงฎ Task 4: Price Calculator

Plan the IPO, choose two conversions, and calculate a total.

Your Goal

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.

Example Input
Notebook
12.5
3
Example Output
3 x Notebook costs 37.5 yuan.

๐ŸŒก๏ธ Task 5: Temperature Converter

Translate a formula into an interactive Python program.

Your Goal

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 to Fahrenheit
F=95C+32F = \dfrac{9}{5}C + 32
Example Output
Celsius temperature: 0
0.0ยฐC = 32.0ยฐF
01 / 25