Table of Contents

Input and output are essential components of any interactive Python program. Whether you’re creating a quiz, calculator, or simple data collection tool, you’ll need to gather input from the user and display results. In Python, input() allows users to provide data, while print() displays it back in a readable format. At the beginner level, mastering I/O teaches you how to structure your code, capture user input, perform type conversions, and present clean, informative output. These are the first steps to making your programs dynamic and user-friendly.

To complete these tasks, you should already be familiar with:

Beginner Level Practice – Input and Output

This beginner section is focused on applying input() and print() in small, real-life inspired programs. You will collect user input, store it in variables, process it slightly, and display personalized messages. These exercises build confidence in handling string input, converting data types, and writing readable output. They also help you get used to the basic flow of asking for data, performing a calculation, and returning feedback to the user. After completing these tasks, you'll be more comfortable writing programs that interact with people in meaningful ways.

Task 1: Ask the User’s Age and Calculate the Next Birthday

Write a program that asks the user to enter their age. Then, use that input to calculate how old they will be next year and display a message like: “Next year you will be 26 years old.” This task helps simulate a basic age calculator and reinforces simple numeric input and output formatting.

What this Task Teaches

This task develops your understanding of how to get numeric input using input() and convert it using int(). You’ll also practice storing values in variables and formatting the output message in a user-friendly way. This builds your ability to turn static text into dynamic, responsive output.

Hints and Tips
  • Use input() to receive a string from the user.
  • Use int() to convert it to an integer.
  • Add 1 to the number and use print() to display the message.
  • Use commas or f-strings to format the message.
Common Mistakes
  1. Forgetting to convert input to an integer: input() always returns a string. If you try to add 1 to it without conversion, you’ll get a TypeError. Always use int() or float() when working with numbers.
  2. Using + for numeric and string concatenation: Trying to mix strings and numbers with + can cause errors. Use f-strings or commas inside print() to combine them.
  3. Invalid input values: If the user types a word instead of a number, int() will crash. You’ll handle that later with error checking.
  4. Not spacing output properly: Beginners often forget to add spaces in the final printed message, leading to results like “Next year you will be25years old”.
  5. Using age as a string throughout: Always convert once and use the numeric version in calculations.
Step-by-Step Thinking

Think through how a user interacts with your program: they type their age, and the system replies with a result. Your job is to capture, process, and return this data.

  1. Ask the user to input their age using input()
  2. Store the result in a variable, e.g., age
  3. Convert the value to an integer using int()
  4. Add 1 to the value to represent next year
  5. Use print() to format and display the message
How to Make it Harder
  • Ask the user for both name and age, and include both in the final output.
  • Format the sentence using f-strings or str.format().
  • Add validation: if the age is not a number, show a warning.

Task 2: Collect and Display a Personalized Message

Write a Python program that asks the user for their name and favorite color. Then display a sentence like: “Hello, Alice! Your favorite color is blue.” This kind of interaction is useful in quizzes, surveys, or welcome messages in applications.

What this Task Teaches

This exercise reinforces how to work with multiple user inputs and store them in separate variables. You’ll also focus on formatting output for clarity and friendliness. It also helps beginners practice clean string concatenation and sequencing of inputs.

Hints and Tips
  • Use input() twice: once for the name, once for the color.
  • Store each value in a clearly named variable.
  • Use print() with commas or f-strings to output the sentence.
  • Capitalize the first letters for aesthetics (optional).
Common Mistakes
  1. Reusing the same variable for both inputs: Make sure you use one variable for the name and a separate one for the color. Otherwise, you’ll overwrite the first input.
  2. Incorrect string formatting: Beginners often forget to add spaces or punctuation in the output, resulting in awkward or unreadable sentences.
  3. Inconsistent casing: If your message uses lowercase names but capitalized greetings, it can look unprofessional. You can optionally use .capitalize() to clean inputs.
  4. Forgetting to test output: Always check what your program prints before finalizing it.
  5. Hardcoding values instead of using variables: Don’t write "Hello, Alice!"; use the name variable instead.
Step-by-Step Thinking

Think about what a user would expect: they provide their name and color, and see a clear message back. Keep it conversational and accurate.

  1. Use input() to ask for the name and save to name
  2. Use input() again to ask for the favorite color and save to color
  3. Format the output message using print()
  4. Insert both variables into the sentence
  5. Test with different names and colors
How to Make it Harder
  • Capitalize both inputs using .capitalize() before displaying them.
  • Ask for three inputs: name, color, and age - and use them all in one sentence.
  • Add emoji or symbols to make the message friendlier.

Intermediate Level Practice – Input and Output

At the intermediate level, input and output operations become more dynamic. You’ll not only read simple values from users, but also format responses, process numerical input, and build logic-driven programs. Tasks at this level mimic real-life tools - like tip calculators or simple scheduling systems - where the flow depends on the user’s answers. This is your chance to apply input() and print() with real computation, conditional logic, and string formatting. You’ll also start thinking about the user experience: how clear is your prompt, how readable is the output?

Task 1: Simple Tip Calculator

Write a program that asks the user for the total bill amount and the desired tip percentage. It should then calculate and display how much tip to leave. For example, if the user enters 100 as the bill and 15 as the tip percent, the program should print: “Leave $15.00 as a tip.”

What this Task Teaches

This task teaches you to process numeric inputs, perform arithmetic with floating-point numbers, and format output with two decimal places. It also helps you write clear prompts and accurate feedback, preparing you to build interactive, user-facing tools.

Hints and Tips
  • Convert inputs to float for decimal calculations.
  • Multiply the bill by the percentage divided by 100.
  • Use round() or string formatting for two decimal places.
  • Be sure your prompts clearly ask for a number, not a string.
Common Mistakes
  1. Forgetting to convert input to float: If you leave the input as a string, trying to multiply it will result in an error. Always use float() before arithmetic.
  2. Incorrect percentage formula: Some beginners mistakenly divide by 100 twice or forget it altogether. Remember: percentage = value × (percent / 100).
  3. Too many or too few decimal places: Output like 15.0000001 looks messy. Use rounding or formatted strings for readability.
  4. Hardcoded values: Don’t use fixed numbers like 0.15 - ask the user for the percentage so they can choose.
  5. Unclear prompts: Always label your inputs (e.g., “Enter bill amount in dollars”) so users know what to do.
Step-by-Step Thinking

You’re building a tool used by people in real life. Think about the flow: get inputs, process them, and return clear, friendly output.

  1. Ask the user for the bill total using input()
  2. Convert the input to float and store it
  3. Ask the user for the desired tip percentage
  4. Convert that input to float as well
  5. Calculate the tip as bill × (percent / 100)
  6. Format the result to two decimal places
  7. Print a message showing the calculated tip
How to Make it Harder
  • Also display the total bill including the tip.
  • Allow the user to choose between tip options (10%, 15%, 20%).
  • Add input validation for non-numeric entries.

Task 2: Time Left Until Bedtime

Ask the user what time it is now (in hours, 24-hour format) and what time they want to go to sleep. Then calculate how many hours are left until bedtime. For example, if it’s 18:00 now and bedtime is 23:00, print: “You have 5 hours left before sleep.”

What this Task Teaches

This task teaches you to handle time-based logic, perform subtraction, and handle special cases like when bedtime is after midnight. It also strengthens your arithmetic thinking using user inputs in a more contextual scenario.

Hints and Tips
  • Use int() or float() to work with hour values.
  • If bedtime is less than current time, add 24 to bedtime before subtracting.
  • Keep your message friendly and use proper time units.
Common Mistakes
  1. Skipping time conversion: If bedtime is 1 and current time is 22, a direct subtraction gives a negative number. Use 24-hour logic by adjusting bedtime when needed.
  2. Incorrect hour format: Beginners sometimes mix formats - like using “8 PM” instead of 20. Be clear that the user must enter numbers from 0 to 23.
  3. Wrong subtraction order: Subtracting current - bedtime gives a negative value. The correct formula is bedtime - current.
  4. Assuming bedtime is always after now: Some people go to sleep after midnight. Handle that with a 24-hour wrap-around.
  5. No type conversion: Don’t try to subtract strings - convert to int or float first.
Step-by-Step Thinking

Imagine a user checking how long until sleep - your program should do the math and return a clean message. Consider edge cases around midnight.

  1. Ask the user for the current hour using input()
  2. Convert the value to int and store it as current_hour
  3. Ask for the bedtime hour and store it as bedtime_hour
  4. If bedtime is less than or equal to current, add 24 to bedtime
  5. Subtract current from bedtime
  6. Display the number of hours left with a friendly message
How to Make it Harder
  • Ask for both hour and minute, and calculate total minutes left.
  • Account for minutes using datetime or manual calculations.
  • Give a recommendation: “It’s getting late! Consider sleeping now.”

Advanced Level Practice – Input and Output

At the advanced level, input and output tasks evolve into mini applications. You’ll need to design clear input flows, handle edge cases, apply conditional logic, and ensure readable, user-friendly output. These exercises combine I/O with core Python structures like loops, conditionals, and data formatting. You’ll simulate realistic systems - like password prompts or budget checkers - where communication with the user is at the center of the program. Precision, clarity, and robustness are key at this level.

Task 1: Multi-Step Login System

Create a login prompt that first asks for a username, then for a password. If both are correct (you can hardcode them, e.g., “admin” and “secret123”), print a success message. If either is wrong, print an error. Optionally, allow the user up to 3 attempts and show how many attempts remain.

What this Task Teaches

You’ll learn how to use multiple input() calls in a logical sequence, apply conditional checks, use loops for retry attempts, and display precise output messages depending on user input. It’s a foundation for authentication logic in real-world software.

Hints and Tips
  • Use two variables to store correct credentials.
  • Use a while loop to limit attempts.
  • Compare inputs with the correct values using ==.
  • Display different messages for incorrect username, password, or both.
Common Mistakes
  1. Using = instead of == in comparisons: This leads to an assignment error or incorrect behavior. Always use == when checking input.
  2. Hardcoding both checks together: Beginners often check both username and password in one line, making it hard to isolate what failed. Separate the logic for better feedback.
  3. Allowing unlimited attempts: Without a counter or loop condition, users can retry forever - always control attempts.
  4. Incorrect string comparison due to whitespace: Users may accidentally type spaces. Use .strip() to sanitize input.
  5. No feedback after failure: A generic "Invalid" message isn’t helpful. Tell the user what went wrong and how many tries are left.
Step-by-Step Thinking

Think like a security system. You must ask, validate, respond - and track user behavior with conditions. Structure your logic for clear user communication.

  1. Define variables for correct username and password
  2. Use a loop that repeats up to 3 times
  3. Ask the user for both username and password using input()
  4. Check both credentials using ==
  5. If correct, display success and break the loop
  6. If incorrect, inform the user and reduce attempts count
  7. After 3 failed tries, show a lockout message
How to Make it Harder
  • Store credentials in a dictionary and support multiple users.
  • Hide password input using a placeholder (e.g., getpass module).
  • Log failed attempts with timestamps.

Task 2: Monthly Budget Evaluator

Build a script that asks the user for their monthly income and expenses across three categories: rent, food, and other. Then calculate the total expense and display whether they are under or over budget. Print a message like: “You are $150 over your budget!” or “You have $120 left this month.”

What this Task Teaches

This exercise involves collecting multiple numeric inputs, performing aggregation, and presenting conditional results. You’ll learn how to guide the user through a step-by-step input flow and summarize their financial data clearly.

Hints and Tips
  • Convert all inputs using float().
  • Sum the expenses to get a total.
  • Compare total expenses with income to determine the result.
  • Use abs() and round() for clean values in output.
Common Mistakes
  1. Not converting inputs: If you forget float(), you’ll be trying to do math with strings, leading to type errors or incorrect results.
  2. Wrong order of operations: Ensure you calculate total expenses before comparing with income.
  3. Unclear user prompts: Always tell the user exactly what data to enter (“Monthly rent in dollars:”) to prevent confusion.
  4. Negative signs in messages: Beginners often write “You have -$100 left”, which sounds confusing. Format output with abs() and proper phrasing.
  5. Not using rounding: Showing too many decimals (e.g., 147.3333333) makes the output unreadable.
Step-by-Step Thinking

Think like a financial tracker: gather clear numbers, sum them, and offer readable results that make sense to the user.

  1. Ask for the monthly income and convert it to float
  2. Ask for three expense inputs: rent, food, and other
  3. Convert each to float and store them
  4. Sum all expenses
  5. Subtract total expenses from income
  6. Use a condition: if result > 0, show “left” message; else show “over” message
  7. Use abs() to display positive values in the message
How to Make it Harder
  • Add more categories (transport, healthcare, entertainment).
  • Display a pie chart of expenses using a library like matplotlib.
  • Allow saving the results to a file or displaying spending suggestions.