-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathfonctions_4.py
More file actions
99 lines (69 loc) · 2.13 KB
/
fonctions_4.py
File metadata and controls
99 lines (69 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
##############################
# Fonctions
##############################
##############################
# Activité 4 - Fonctions
##############################
##################################################
## Question 1 ##
def reduction(age):
""" Renvoie le pourcentage de réduction en fonction de l'âge """
if age < 10:
reduc = 50
elif age <= 18:
reduc = 30
elif age >= 60:
reduc = 20
else:
reduc = 0
return reduc
# Test
print("--- Réduction ---")
mon_age = 16
print("J'ai",mon_age,"ans et ma réduction est de",reduction(mon_age),"%.")
##################################################
def montant(tarif_normal,age):
""" Calcule le montant dû, en fonction du tarif normal et de l'âge """
reduc = reduction(age)
tarif = tarif_normal * (100-reduc)/100
return tarif
# Test
print("--- Coût total des billets ---")
montant_famille = montant(30,9) + 2*montant(20,16) + 2*montant(35,40)
print(montant_famille)
##################################################
## Question 2 ##
def calcul_est_exact(a,b,reponse):
""" Teste si le résultat de a*b est correct """
if reponse == a * b:
return True
else:
return False
# Test
print("--- Test résultat multiplication ---")
print(calcul_est_exact(6,7,42))
def test_multiplication(a,b,lang):
""" Pose une multiplication en français ou en anglais
et affiche si la réponse est correcte ou pas """
# Phrases en français et en anglais
if lang == "francais":
question = "Combien vaut le produit a x b ? "
reponse_juste = "Bravo !"
reponse_fausse = "Eh non !"
if lang == "anglais":
question = "How much is the product a x b? "
reponse_juste = "Well done!"
reponse_fausse = "It's wrong!"
# Interrogation
print("--- Question ---")
print("a =",a)
print("b =",b)
reponse = int(input(question))
if calcul_est_exact(a,b,reponse):
print(reponse_juste)
else:
print(reponse_fausse)
return
# Test
print("--- Quiz multiplication français/anglais ---")
test_multiplication(6,7,"anglais")