Looking for 25-In211-Pratique de la programmation en Python 1- test answers and solutions? Browse our comprehensive collection of verified answers for 25-In211-Pratique de la programmation en Python 1- at moodle.ipsa.fr.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Qu'affiche le code python suivant?
def access(user): match user: case "admin" | "manager": return "Full access." case "Guest": return "Limited access." case _: return "No access."
print(access('User'))print(access('manager'))
Qu'affiche le code Python suivant ?
def ee(*ops, **kwargs):
strict = kwargs.get("strict", False)
results = []
for op in ops:
match op:
case ("add", x, y):
results.append(x + y)
case ("sub", x, y):
results.append(x - y)
case ("mul", x, y):
results.append(x * y)
case ("div", x, y):
try:
results.append(x / y)
except ZeroDivisionError:
if strict:
raise ZeroDivisionError
results.append(None)
case _:
pass
return results
print(ee(("add", 2, 3), ("mul", 3, 4)),
ee(("div", 1, 0), ("div", 4, 2)),
ee(("noop",), ("sub", 5, 2), ("div", 10, 5)))
Qu'affiche le code Python suivant ?
def cc(*cmds):
stack = []
outputs = []
for c in cmds:
match c:
case ("push", x):
stack.append(x)
case ("pop",):
if stack:
outputs.append(stack.pop())
case ("sum",):
if len(stack) >= 2:
a = stack.pop()
b = stack.pop()
stack.append(a + b)
case _:
pass
return outputs
print(cc(("push", 1), ("pop",), ("pop",)),
cc(("push", 1), ("push", -1), ("sum",), ("pop",)),
cc(("pop",),))
Le constructeur d'une classe correspond à :
Analysez le code suivant et identifiez le(s) problème(s) potentiel(s) :
data = json.load(file) print(f"Clé introuvable : {e}")import jsonfile = open("data.json", "r") print(data["key"])print("Fichier non trouvé") file.close()
Quelle affichage produit le code python suivant?
D = {'pomme': 3, 'orange': 6, 'tomate': 2}try: x = D['banane'] print(x)except TypeError: print("Error1")except KeyError: print("Error2")Qu'affiche le code python suivant?
def http_response(status): match status: case 200 | 201: return "Success" case 500 | 502 | 503: return "Server Error" case _: return "Unknown Status"
print(http_response(500)) print(http_response(202))