0% found this document useful (0 votes)
13 views

Python

The document contains definitions for several Python functions: 1. It defines functions for calculating the factorial of a number, reversing a list, finding the maximum number of consecutive zeros in a list, determining if a number is prime, calculating the sum of divisors of a number, determining if a number is perfect, finding the nth perfect number, determining the majority element of a list, calculating Fibonacci numbers, and simulating rolling dice. 2. The functions perform various numeric, list, and statistical calculations and operations. 3. The document appears to contain Python code definitions for several mathematical and computational functions.

Uploaded by

Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Python

The document contains definitions for several Python functions: 1. It defines functions for calculating the factorial of a number, reversing a list, finding the maximum number of consecutive zeros in a list, determining if a number is prime, calculating the sum of divisors of a number, determining if a number is perfect, finding the nth perfect number, determining the majority element of a list, calculating Fibonacci numbers, and simulating rolling dice. 2. The functions perform various numeric, list, and statistical calculations and operations. 3. The document appears to contain Python code definitions for several mathematical and computational functions.

Uploaded by

Paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#

/Users/paul/Correction DS.py
01| def factorielle(n):
02| A=1
03| for k in range (1,n+1):
04| A=A*k
05| return A
06|
07| def miroir(L):
08| A=len(L)
09| for k in range (A):
10| L.append(L[A-k-1])
11| return L
12|
13| def Zeros(t):
14| L=[]
15| compteur=0
16| for k in range (len(t)):
17| if t[k]==0:
18| compteur=compteur+1
19| else:
20| L.append(compteur)
21| compteur=0
22| print (L)
23| return max(L)
24|
25| def premier(n):
26| for k in range (2,n):
27| if n%k==0 and k!=0:
28| return False
29| else:
30| return True
31|
32| def somme_div(n):
33| L=[]
34| for k in range (2,n):
35| if n%k==0:
36| L.append(k)
37| return sum(L)
38|
39| def parfait(n):
40| if somme_div(n)==n-1:
41| return True
42| else:
43| return False
44|
45| def enieme_parfait(n):
46| c=0
47| t=1
48| while c!=n:
49| if parfait(t)==False:
50| t=t+1
1
51| else:
52| c=c+1
53| t=t+1
54| return t-1
55|
56| def majoritaire(L):
57| moitie=len(L)//2
58| test=0
59| compteur=0
60| x=0
61| for k in range (len(L)):
62| test=L[k]
63| compteur=0
64| for p in range (len(L)):
65| if L[p]==test:
66| compteur=compteur+1
67| if compteur>moitie:
68| x=L[k]
69| if x==0:
70| return None
71| else:
72| return x
73|
74| def fibo(n):
75| A=0
76| B=1
77| C=0
78| for k in range(1,n):
79| A=B+C
80| C=B
81| B=A
82| return A
83|
84| def lances_de_des(n):
85| from random import randint
86| A=0
87| for k in range(n):
88| A=A+randint(1,6)
89| return A
90|
91|
92|
93|
94|

You might also like