mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-09 11:30:38 +00:00
first commit
This commit is contained in:
28
recurivite/TD1.py
Normal file
28
recurivite/TD1.py
Normal file
@@ -0,0 +1,28 @@
|
||||
def factorielle(number: int):
|
||||
if number == 0:
|
||||
return 1
|
||||
else:
|
||||
return number * factorielle(number-1)
|
||||
|
||||
def modulo(a, b):
|
||||
if b-a < 0:
|
||||
return b
|
||||
elif b == 0:
|
||||
return b
|
||||
else:
|
||||
return modulo(a,b-a)
|
||||
def somme(n):
|
||||
if n == 0:
|
||||
return n
|
||||
else:
|
||||
return(n+somme(n-1))
|
||||
def init_quotient(a,b):
|
||||
i = 0
|
||||
return (quotient(a,b,i))
|
||||
def quotient(a,b,i):
|
||||
if b == 0 or b-a < 0:
|
||||
return i
|
||||
else:
|
||||
return(quotient(a,b-a,i+1))
|
||||
|
||||
print(init_quotient(6,18))
|
||||
12
recurivite/exercice_MJoannic/palindrom.py
Normal file
12
recurivite/exercice_MJoannic/palindrom.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def is_palindrom(word)->bool:
|
||||
word = list(word)
|
||||
if len(word) < 2:
|
||||
return True
|
||||
if word[0] == word[-1]:
|
||||
word.pop(0)
|
||||
word.pop(-1)
|
||||
return is_palindrom(word)
|
||||
else:
|
||||
return False
|
||||
|
||||
print(is_palindrom("do geese see god".replace(' ', '')))
|
||||
Reference in New Issue
Block a user