-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathfonctions_cours.py
More file actions
110 lines (70 loc) · 1.55 KB
/
fonctions_cours.py
File metadata and controls
110 lines (70 loc) · 1.55 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
##############################
# Fonctions
##############################
##############################
# Cours 1
##############################
##################################################
def dit_bonjour():
print("Bonjour le monde !")
return
# Appel
dit_bonjour()
dit_bonjour()
##################################################
def affiche_carres():
for i in range(20):
print(i**2)
return
# Appel
affiche_carres()
##############################
# Cours 2
##############################
##################################################
def affiche_mois(numero):
if numero == 1:
print("Nous sommes en janvier.")
if numero == 2:
print("Nous sommes en février.")
if numero == 3:
print("Nous sommes en mars.")
# etc.
return
# Appel
affiche_mois(2)
##################################################
def calcule_cube(a):
cube = a * a * a # ou bien a**3
return cube
# Appel
x = 3
y = 4
z = calcule_cube(x) + calcule_cube(y)
print(z)
##############################
# Cours 2
##############################
##################################################
def somme_produit(a,b):
"""Calcule la somme et le produit de deux nombres"""
s = a + b
p = a * b
return s, p
# Appel
som, pro = somme_produit(6,7)
print(som,pro)
##############################
# Cours - Variable locale
##############################
x = 7
def plus_un(x):
x = x + 1
return x
def double(x):
x = 2*x
return x
print(x)
print(plus_un(x))
print(double(x))
print(x)