(Soluzioni subito sotto ogni esercizio)
Un utente può accedere se ha almeno 18 anni.
Crea una condizione che stampi “Allowed” se l’utente può accedere.
age = 20
if age >= 18:
print("Allowed")
else:
print("Denied")
Uno sconto è applicabile se:
price = 7
stock = 5
if price < 10 and stock > 0:
print("Discount available")
Un ragazzo può entrare in un evento se:
age = 15
with_parent = True
if age >= 16 or with_parent:
print("Access granted")
Un software deve verificare se:
expired = False
if not expired:
print("License valid")
Mostra un warning se:
sensor_active = True
motion_detected = True
if sensor_active and motion_detected:
print("Warning! Movement detected.")
Un ordine è valido se:
registered = True
payment_added = True
if registered and payment_added:
print("Order valid")
Stampa “OK” se la temperatura è tra 18 e 30 gradi (compresi).
temp = 25
if 18 <= temp <= 30:
print("OK")
Mostra “Access denied” se:
banned = False
valid_id = False
if banned or not valid_id:
print("Access denied")
Controlla che la lista degli acquisti contenga sia latte che cereali.
cart = ["milk", "eggs", "cereal"]
if "milk" in cart and "cereal" in cart:
print("Breakfast ready!")
Una password è accettabile se:
password = "test@123"
if len(password) >= 8 and ("@" in password or "#" in password):
print("Password ok")
L’utente può accedere ai contenuti premium se:
subscribed = False
access_code_valid = True
suspended = False
if (subscribed or access_code_valid) and not suspended:
print("Premium content unlocked")
Mostra “Device failure” se:
temp = 85
battery = 3
maintenance_mode = False
if (temp > 80 or battery < 5) and not maintenance_mode:
print("Device failure")
Un login è consentito se:
username = "admin"
password = "1234"
blocked = False
override = False
if (username != "" and password != "" and not blocked) or override:
print("Login ok")
Un prodotto è di categoria “valid” se:
product = "Alto"
if (product.startswith("A") and len(product) >= 3) or product.endswith("x"):
print("Valid product")
L’allarme deve suonare se:
door_open = True
password_entered = False
intruder_detected = False
if (door_open and not password_entered) or intruder_detected:
print("Alarm ON")