Bonjour
Alors voilà je suis débutant en Python et j'ai un exercice qui me demande de remplacer les répétition par la fonction liste mais je n'arrive pas à comprendre comment l'utilisé :/
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 from random import * from math import * n=int(input("n=")) a=0 b=0 c=0 d=0 e=0 f=0 g=0 h=0 j=0 k=0 l=0 for i in range(1,n+1): r=randint(1,6)+randint(1,6) if r==2: a=a+1 if r==3: b=b+1 if r==4: c=c+1 if r==5: d=d+1 if r==6: e=e+1 if r==7: f=f+1 if r==8: g=g+1 if r==9: h=h+1 if r==10: j=j+1 if r==11: k=k+1 if r==12: l=l+1 print("2:"+str(a)) print("3:"+str(b)) print("4:"+str(c)) print("5:"+str(d)) print("6:"+str(e)) print("7:"+str(f)) print("8:"+str(g)) print("9:"+str(h)) print("10:"+str(j)) print("11:"+str(k)) print("12:"+str(l))
Partager