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’: …
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’: …
Use this dictionary: marks = {“Selam”: 88, “Abel”: 45, “Merhawi”: 91, “Lidya”: 38} Create an empty list called passed. Loop with items(). A mark of 50 or more is a pass. Print Name – PASS or Name – FAIL, and …
Use the dictionary below: marks = {“Selam”: 88, “Abel”: 74, “Merhawi”: 91} Loop with items() and print each student as Name: mark. Inside the same loop, add each mark to a variable called total (start it at 0). After the …
A shop in Massawa keeps its stock in a dictionary: stock = {“bread”: 30, “milk”: 0, “tea”: 14, “salt”: 0, “rice”: 8} Create an empty list called sold_out. Loop over a list copy of the keys. For every item with …
