Hana scored 72, 80 and 88 in three tests. The program below calculates her average, but the answer is wrong because of operator precedence. Fix the line that creates average by adding parentheses. Expected output: 80.0
Three variables are given. list3 is not a copy — it is another name for list1. Create four booleans: same_values — whether list1 and list2 have equal values (==). same_object — whether list1 and list2 are the same object (is). …
Use membership and identity operators to create three booleans: invited — True when visitor is in the list guests. has_z — True when the letter “z” is in the string visitor. no_phone — True when phone is None (use is). …
A shop in Massawa is open from Monday to Saturday, from 8 to 18 o’clock (8 <= hour < 18), but it closes for lunch from 12 to 14 (12 <= hour < 14). Customers can use the phone line …
Abel wants to join the under-17 football team in Keren. The rules are: age from 12 to 16, permission from a parent, and not injured. Create right_age using and: age is at least 12 and at most 16. Create can_play: …
A school website saved the name “Merhawi” and the PIN “4821” (a string). The student typed the name “merhawi” and the PIN 4821 (an integer). Create three booleans: exact_name — whether the typed name is exactly the saved name. same_name …
A youth concert in Asmara has rules for tickets. Given age = 16, money = 100 and ticket_price = 80, create three boolean variables using comparisons: is_teen — True when age is from 13 to 19 (use a chain). can_afford …
Build a banner for a festival using only += and *= to change the variables: Start with banner = “Keren” and add ” Festival” to it with +=. Start with border = “*” and repeat it with *= so it …
Selam has 200 Nakfa in her wallet. Change the variable wallet using shortcut assignment operators, one line for each event: She earns 150 Nakfa (+=). She spends 80 Nakfa at the market (-=). She shares the money equally with her …
A runner from Keren finished a long race in 7384 seconds. Turn this into hours, minutes and seconds. hours — whole hours (3600 seconds in an hour). minutes — whole minutes left after taking away the hours. seconds — seconds …
