Python Exercises With Solutions Recreated
Python Exercises With Solutions Recreated
1. Birthday Invitations:
- Create a list of 5 friends' names (e.g., 'Alice', 'Bob', 'Charlie', 'Dana', 'Eve').
- Print a message for each friend: 'Hi <name>, you are invited to my birthday party!'
# Solution
Write a Python program to count the total number of apples in multiple baskets:
- Assume you have 5 baskets, each containing a different number of apples (e.g., [5, 8, 3, 10,
7]).
# Solution
total_apples = 0
total_apples += apples
- Print a greeting message for each classmate: 'Hello <name>, good to see you!'
# Solution
Write a Python program to track your daily water intake for a week and check if you met your
- Create a list with the amount of water you drank each day for 7 days (e.g., [2.5, 1.8, 2.0, 1.5,
- 'Day <day_number>: You drank enough water!' if the intake is 2 liters or more.
- 'Day <day_number>: Drink more water tomorrow!' if the intake is less than 2 liters.
# Solution
else:
5. Magic Numbers:
Write a Python program to display the first 5 multiples of a number entered by the user:
- Ask the user to input a number.
- Use a for loop to generate and print the first 5 multiples of the number.
12
15
# Solution
print(number * i)
6. Collecting Coins:
- Create a list with the number of coins in each treasure chest (e.g., [50, 120, 90, 30]).
- Use a for loop to print how many coins each chest contains, with the message:
# Solution
Write a Python program to check if a list of guesses contains the secret number:
- Define a secret number (e.g., 7).
- Print:
# Solution
secret_number = 7
if guess == secret_number:
else:
8. Candy Distribution:
- Use a for loop to print how many candies each child gets, with the message:
# Solution
total_candies = 15
children = 3
- Use a for loop to print one additional star (*) in each line.
**
***
****
*****
# Solution
print('*' * i)
Write a Python program to count down the days until a vacation starts:
'5 days left...', '4 days left...', and so on, until it reaches: 'Vacation starts now!'.
# Solution
days_left = 5