Practice Problems: Input, Output & String Formatting
15 problems to reinforce your learning • Try each one before checking the solution!
Problem 1 Easy
Use print() with the sep parameter to display today's date in the format 03/21/2025 using three separate values for month, day, and year.
month = "03" day = "21" year = "2025" print(month, day, year, sep="/")
Problem 2 Easy
Print the words "Python", "is", "fun" on a single line using three separate print() calls and the end parameter.
print("Python", end=" ") print("is", end=" ") print("fun")
Problem 3 Easy
Write a program that asks the user for their name and prints a greeting using an f-string.
name = input("What is your name? ") print(f"Hello, {name}! Welcome to Python!")
Problem 4 Easy
Ask the user for two numbers and print their sum. Remember that input() returns a string!
Convert the inputs to numbers using int() or float() before adding.
num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) print(f"{num1} + {num2} = {num1 + num2}")
Problem 5 Easy
Use an f-string to format the number 1234567.891 with commas and 2 decimal places.
number = 1234567.891 print(f"{number:,.2f}")
Problem 6 Medium
Write a tip calculator: ask for the bill amount and tip percentage, then display the tip amount and total, both formatted to 2 decimal places with a dollar sign.
Tip = bill * (percentage / 100). Use f"${value:.2f}" for currency formatting.
bill = float(input("Bill amount: $")) tip_pct = float(input("Tip percentage: ")) tip = bill * (tip_pct / 100) total = bill + tip print(f"Tip: ${tip:.2f}") print(f"Total: ${total:.2f}")
Problem 7 Medium
Ask the user for their name and a number. Print their name repeated that many times, separated by spaces.
Use (name + " ") * n for repetition. Convert the number input to int().
name = input("Enter your name: ") n = int(input("How many times? ")) print((name + " ") * n)
Problem 8 Medium
Display a student's score as a percentage. Ask for the points earned and total points possible. Format the result to 1 decimal place.
earned = float(input("Points earned: ")) total = float(input("Total points possible: ")) percentage = earned / total print(f"Your score: {percentage:.1%}")
Total points possible: 100
Your score: 85.0%
Problem 9 Medium
Create a formatted table that shows 3 items with their prices, right-aligned. Use f-string alignment.
Use f"{'text':<width}" for left alignment and f"{'text':>width}" for right alignment.
print(f"{'Product':<15} {'Price':>10}") print("-" * 26) print(f"{'Notebook':<15} {'$4.99':>10}") print(f"{'Pen Pack':<15} {'$2.49':>10}") print(f"{'Eraser':<15} {'$0.99':>10}")
Problem 10 Medium
Write a Mad Libs program that asks for a noun, verb, adjective, and place name, then prints a silly sentence using those words.
noun = input("Enter a noun: ") verb = input("Enter a verb: ") adjective = input("Enter an adjective: ") place = input("Enter a place: ") print(f"\nThe {adjective} {noun} decided to {verb} all the way to {place}!")
Problem 11 Medium
Use the .format() method (not f-strings) to print: "Hello, Alice! You scored 92.5% on the test."
name = "Alice" score = 0.925 print("Hello, {}! You scored {:.1%} on the test.".format(name, score))
Problem 12 Challenge
Write a program that asks for length and width in feet, then displays the area in both square feet and square meters (1 sq ft = 0.0929 sq m). Format numbers to 2 decimal places.
Calculate area in sq ft first, then multiply by 0.0929 for sq meters.
length = float(input("Enter length (ft): ")) width = float(input("Enter width (ft): ")) area_ft = length * width area_m = area_ft * 0.0929 print(f"Area: {area_ft:.2f} sq ft") print(f"Area: {area_m:.2f} sq m")
Problem 13 Challenge
Build a string incrementally using +=. Start with an empty string and add 5 lines to create a numbered list. The output should look like:
goals = "" goals += "1. Learn Python\n" goals += "2. Practice daily\n" goals += "3. Build projects\n" goals += "4. Read documentation\n" goals += "5. Help others" print(goals)
Problem 14 Challenge
Create a temperature converter that asks for Celsius, then displays Fahrenheit and Kelvin. Use a bordered output with f-string formatting. Formula: F = C * 9/5 + 32, K = C + 273.15
celsius = float(input("Enter temperature in Celsius: ")) fahrenheit = celsius * 9 / 5 + 32 kelvin = celsius + 273.15 print() print("=" * 30) print(" Temperature Conversion") print("=" * 30) print(f" Celsius: {celsius:.1f} C") print(f" Fahrenheit: {fahrenheit:.1f} F") print(f" Kelvin: {kelvin:.1f} K") print("=" * 30)
Problem 15 Challenge
Create a mini invoice program. Ask the user for 3 item names and their prices. Display a formatted invoice with aligned columns and a total at the bottom.
Use f-string alignment: f"{'text':<20}" for left-aligned text and f"{value:>10.2f}" for right-aligned numbers.
item1 = input("Item 1 name: ") price1 = float(input("Item 1 price: $")) item2 = input("Item 2 name: ") price2 = float(input("Item 2 price: $")) item3 = input("Item 3 name: ") price3 = float(input("Item 3 price: $")) total = price1 + price2 + price3 print() print("=" * 32) print(f"{'INVOICE':^32}") print("=" * 32) print(f" {item1:<20} ${price1:>7.2f}") print(f" {item2:<20} ${price2:>7.2f}") print(f" {item3:<20} ${price3:>7.2f}") print("-" * 32) print(f" {'TOTAL':<20} ${total:>7.2f}") print("=" * 32)