0% found this document useful (0 votes)
2 views4 pages

Exemples Suitev2

The document contains various examples of Python code demonstrating loops and input handling. It includes examples of summing numbers, validating user input, and calculating terms in a sequence. Additionally, it showcases exercises related to mathematical computations such as finding a square root and calculating a series.
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)
2 views4 pages

Exemples Suitev2

The document contains various examples of Python code demonstrating loops and input handling. It includes examples of summing numbers, validating user input, and calculating terms in a sequence. Additionally, it showcases exercises related to mathematical computations such as finding a square root and calculating a series.
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/ 4

Exemple 1 ¶

Entrée [1]: 1 n = 10
2 s = 0
3 while n > 0 :
4 s = s + n
5 n = n - 1
6 print(s)

55

Entrée [3]: 1 n = 10
2 s = 0
3 while True :
4 s = s + n
5 n = n - 1
6 if n <= 0 :
7 break
8 print(s)

55

Exemple 2 :
Entrée [4]: 1 # saisie de n > 0
2 n = int(input("donner n : "))
3 while not(n > 0 ) :
4 n = int(input("donner n : "))

donner n : -8
donner n : -9
donner n : 14

Entrée [5]: 1 while True :


2 n = int(input("donner n : "))
3 if n > 0 :
4 break

donner n : -4
donner n : -7
donner n : -2
donner n : 6

Ex 1 Catalan
Entrée [6]: 1 k = 0
2 n = 0
3 while True :
4 terme = (-1)**n/(2*n+1)**2
5 k = k + terme
6 if abs(terme) < 10**-6 :
7 break
8 n = n + 1
9
10 print(k)

0.9159660921817144

Ex 2 BG
Entrée [7]: 1 while True :
2 n = int(input("donner n : "))
3 if n > 2 :
4 break

donner n : 6

Entrée [9]: 1 U = 1 # i = 1
2 V = 2 # i = 2
3 S = U+V
4 for i in range(3 , n+1) :
5 terme = U + V
6 S = S + terme
7
8 U = V
9 V = terme
10
11 print(S)

32

Exemple Suite
U0 = 1
Un = 3Un-1 + 2

1. saisir n > 1
2. calculer la somme des termes
3. calculer le produit des termes

Entrée [37]: 1 while True :


2 n = int(input("donner n : "))
3 if n > 1 :
4 break

donner n : 3
Entrée [ ]: 1 ​
2 U = 1 # U0
3 S = U
4 print("termes = ", end = ' ')
5 for i in range(1 , n+1) :
6 terme = 3*U + 2
7 print(terme, end = ',')
8 S = S + terme
9 U = terme
10
11 print("\nsomme = ", S)

Entrée [ ]: 1 ​

Entrée [40]: 1 P = 1
2 U = 1 # U0
3 for i in range( 1 , n+1) :
4 terme = 3*U + 2
5 P = P * terme
6 U = terme
7 print(P)

4505

Entrée [41]: 1 5*17*53

Out[41]: 4505

Exercice :

Entrée [42]: 1 while True :


2 A = int(input("donner A : "))
3 if A > 0 :
4 break

donner A : 25
Entrée [45]: 1 U = 1
2 eps = 10**-1
3 while True :
4 V = (U+A/U)/2
5 if abs(V-U)/U < eps :
6 break
7 U = V
8
9 print(V)

5.015247601944898

Exercice Sinus

Entrée [ ]: 1 ​

You might also like