###### tags: `tp`
:::success
# TP n°1 : les fonctions
:::
[pages d'exos](https://hackmd.io/@SOmMDwrmTHewWN2IEOBvnA/Hk9qRYhxj)
:::info
# Exercice n°1
```python=
a=2 + 3 * 5 + 4
b=(5 + 2) * 3 + 4
c=4 + 5 * (2 + 3)
print(a,b,c)
```
# Exercice n°2
```python=
# x = 0 :
#x = 0
x = 10
print(x < 10 and x > -10) # x = 0 : True x = 10 : False
print(x < 10 or x > -10) # x = 0 : True x = 10 : True
print(x < 10 and x > -10 or x <= -10 and x > -15 and x == 10 and x >= -10) # x = 0 : True x = 10 : False
```
# Exercice n°3
```python=
# 1re boucle
s = 0
for i in range(10):
s = s + i
print(s)
# s'éxecute 10 fois || s= 45
# 2e boucle
s = 1
for i in range(1,6):
s = s * i
print(s)
#1; 2; 6; 24; 120
# s'éxecute 5 fois || s=120
# 3e boucle
s = 0
while s < 20 :
s = s + 5
print(s)
#5; 10; 15; 20
#s'execute 4 fois || s= 20
# 4e boucle
s = 0
while s != 100 :
s = s * 2
print(s)
#000000000000000000000000000
#s'execute infini fois || s= 0
```
# Exercice n°4
```python=
pi = 3,14
def cicrconference(rayon):
return pi*r*2
print(circonference(10))
# errors : point a la place de virgule; nom de fonciton trop long; faute dans le nom de fonction; rayon != r; return avant le print
pi = 3.14
def circon(r):
return pi*r*2
print(circon(10))
```
# Exercice n°5
```python=
#1.
annee = int(input("nombre de l'année"))
if (annee%4==0 and annee%100!=0 or annee%400==0):
print("l'année", annee, "est bisextile")
else:
print("l'année", annee, "n'est pas bisextile")
#2.
def nb_jours_mois(mois,annee):
if mois in [4,6,9,11]:
return(30)
elif mois in [1,3,5,7,8,10,12]:
return(31)
elif (annee%4==0 and annee%100!=0 or annee%400==0):
return(29)
else:
return(28)
print(nb_jours_mois(12,2013))
```
# Exercice 6
```python=
def decrementer(n):
while n>=0:
print(n)
n= n-1
decrementer(5)
```
# Exercice n°7
```python=
def affiche_pairs(n):
if n%2==0:
while n>=0:
print(n)
n = n-2
else:
while n>=0:
print(n)
n = n-2
affiche_pairs(7)
```
:::