Anatomy of Getting Input
The `input()` function lets your program ask the user for information. Click the parts below to identify them.
Focus: Interaction.
Identify all 6 parts!
Input & Output Flow
See how `input()` works with `print()`. Write code to ask for a favorite color, then print a message using it. Enter a sample color in the "Simulated Input" box *before* running.
The Type Mystery
`input()` always gives back text (a string), even if the user types numbers! This can cause surprises. Predict the outcome for each case below.
Focus: Data Manipulation (Types).
Case 1: Adding Numbers?
Imagine the user enters '5' when asked for `num1` and '3' for `num2`.
What will be printed?
Case 2: The Fix with `int()`
Now we use `int()` to convert the input. User enters '10' then '4'.
What will be printed?
Practice Type Conversion
Now you try! Write code to ask the user for their birth year. Convert it to an integer using `int()`, calculate their approximate age in 2024, and print the age. Use the simulator below.
Focus: Interaction & Data Manipulation.
Input Mini Missions!
Combine `input()` and type conversion to solve these tasks. Enter sample input before testing each mission!
Mission 1: Simple Greeting
Ask the user for their name and print a greeting like "Hello, [Name]!". (No type conversion needed here!)
Mission 2: Age Next Year
Ask the user for their current age (as a number). Convert it to an integer using `int()` and print their age next year.
Mission 3: Price + Tax
Ask for an item price (can have decimals). Convert it to a float using `float()`. Calculate a 10% tax (price * 0.10) and print *only* the tax amount.
Module 4 Practice Complete!
Excellent work! You've practiced getting user input and handling different data types.
Ready for a bigger challenge? Try the Advanced Practice for Module 4!