-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascal.py
More file actions
38 lines (28 loc) · 877 Bytes
/
pascal.py
File metadata and controls
38 lines (28 loc) · 877 Bytes
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
# affiche N lignes du Triangle de Pascal
# avec les vérifications pour être sûr que N est un entier
# fonction pour calculer une factorielle
def factorielle(x):
if x == 0:
return 1
else:
facto = 1
for i in range(2, x+1):
facto = facto * i
return facto
# programme principal
while True:
try:
n = int(input("Combien de lignes voulez-vous afficher (0 pour quitter)? "))
except ValueError as e:
print("Vous devez indiquer un entier !- %s" % e)
else:
print()
if n == 0:
print('fin du programme.\n')
break
for n in range(n+1):
for k in range(n+1):
resultat = int(factorielle(n)/(factorielle(k) * factorielle(n-k)))
print(f"{resultat} ", end="")
print()
print()