The secret number is 7. A player’s guesses are stored in a list (there is no input() in the editor): guesses = [3, 9, 7, 5] Use a while loop with an index to check the guesses one by one: …
Selam saves 200 Nakfa every month. She needs at least 1500 Nakfa. Use a while loop to find out how many months she needs. Start with savings = 0 and months = 0. In each round, add 200 to savings …
Each task is a tuple (a, operator, b). Loop through tasks and use match on the operator: “+”, “-“, “*”: calculate the result. “/” with a guard if b != 0: calculate a / b. “/” (when b is 0): …
Days are numbered from 1 (Monday) to 7 (Sunday). Given day = 6, use match to create a variable kind: “Weekday” for 1, 2, 3, 4 or 5 (one case with |) “Weekend” for 6 or 7 (one case with …
A bus from Asmara to Massawa has these fares: Under 5 years old: 0 Nakfa 5 to 17 years old: 30 Nakfa 60 years or older: 40 Nakfa Everyone else (adults): 60 Nakfa, but adult students pay 20 Nakfa less …
Given mark = 78: Use if/elif/else to create a variable grade: “A” for 90 and above, “B” for 80 and above, “C” for 70 and above, “D” for 50 and above, otherwise “F”. Create result with a ternary operator: “pass” …
Each tuple below holds a student’s name and city: students = [(“Selam”, “Asmara”), (“Abel”, “Keren”), (“Merhawi”, “Asmara”), (“Lidya”, “Massawa”), (“Yonas”, “Keren”), (“Ruth”, “Asmara”)] Create a dictionary called by_city where each city is a key and the value is a list …
Start with this list: subjects = [“math”, “english”, “science”] Create marks with dict.fromkeys() so that every subject starts at 0. Use update() to set math to 85 and science to 78. Use setdefault() to add “art” with the value 60. …
A school football team is stored as a nested dictionary: team = { “Selam”: {“city”: “Asmara”, “goals”: 4}, “Abel”: {“city”: “Keren”, “goals”: 7}, “Merhawi”: {“city”: “Massawa”, “goals”: 2} } Print Abel’s city. Merhawi scored one more goal: add 1 to …
The starter code has a bug: changing new_prices also changes prices. Press Run to see it. Fix the program by making new_prices a real copy with copy(). Keep the two changes. The output must be: {‘bread’: 10, ‘milk’: 25} {‘bread’: …
