Operators are special symbols and keywords that help perform an operation or computation on one or more values or variables.
The values or variables that the operator works on are called operands.
Arithmetic operators are used with numeric values to perform common mathematical calculations.
Imagine you are buying movie tickets for a weekend outing. Write a Python program that asks for the movie details, calculates the total cost, and prints out a receipt.
Write a Python program that does the following:
Ask for Input:
Ask the user for the movie name (text).
Ask the user for the price of one ticket (decimal number/float).
Ask the user how many tickets they want to buy (whole number/integer).
Calculate:
Multiply the ticket price by the number of tickets to find the total cost.
Print the Receipt:
Use an f-string to display the movie name, ticket count, and total cost.
Use a dashed line ("-" * 25) to make your output look neat.
--- Movie Ticket Calculator ---
Enter movie name: Space Adventure
Enter price per ticket ($): 10.50
How many tickets?: 3
-------------------------
Movie: Space Adventure
Tickets: 3
Total Cost: $31.5
Enjoy your movie!
-------------------------
Solution
Imagine you are planning a road trip to a new city. Write a Python program that helps you figure out how many litres of fuel your car will need to get there based on the distance in kilometers and your car's fuel efficiency.
Write a Python program that does the following:
Ask for Input:
Ask the user for the destination city name (text).
Ask the user for the total distance in kilometers (decimal number/float).
Ask the user for their car's fuel efficiency in kilometers per litre, or km/L (decimal number/float).
Calculate:
Divide the total distance by the car's km/L efficiency to find out how many litres of fuel are needed.
Print the Summary:
Use an f-string to display the destination, distance, and total fuel required.
Use a dashed line ("-" * 25) to make your output look neat.
--- Road Trip Fuel Calculator ---
Enter destination city: Beach Town
Enter total distance (km): 150.0
Enter car fuel efficiency (km/L): 15.0
-------------------------
Destination: Beach Town
Distance: 150.0 km
Fuel Required: 10.0 litres
Have a safe and fun trip!
-------------------------
Solution
You are helping a local bakery pack their fresh cookies into boxes to sell. Every box needs an exact number of cookies, but sometimes there are extra cookies left over that don't fill a whole box. Write a program that calculates how many full boxes can be packed and how many loose cookies remain.
Write a Python program that does the following:
Ask for Input:
Ask the user for the total number of cookies baked (whole number/integer).
Ask the user how many cookies fit into one box (whole number/integer).
Calculate:
Use floor division (//) to find out how many full boxes can be packed.
Use the modulus operator (%) to find out how many leftover cookies are left.
Print the Summary:
Use an f-string to display the number of full boxes and leftover cookies.
Use a dashed line ("-" * 25) to make your output look neat.
--- Bakery Box Packer ---
Enter total cookies baked: 50
Enter cookies per box: 12
-------------------------
Full Boxes Ready: 4
Leftover Cookies: 2
Ready for delivery!
-------------------------
Solution
Imagine you are building a financial helper app for a savings bank. You want to help users calculate how much extra money (interest) they will earn on their savings account over a certain period of time.
Write a Python program that does the following:
Ask for Input:
Ask the user for the principal amount (the starting money, as a float).
Ask the user for the annual interest rate (as a percentage, e.g., 5.0 for 5%, as a float).
Ask the user for the time in years (as a float or integer).
Calculate:
Calculate the simple interest using the formula: Interest = (Principal × Rate × Time) / 100
Calculate the final total amount by adding the interest to the original principal.
Print the Summary:
Use an f-string to display the interest earned and the final total amount.
Use a dashed line ("-" * 25) to make your output look neat.
--- Simple Interest Calculator ---
Enter principal amount ($): 1000.0
Enter annual interest rate (%): 5.5
Enter time in years: 3.0
-------------------------
Principal: $1000.0
Interest Earned: $165.0
Total Amount: $1165.0
Financial planning made easy!
-------------------------
Solution