CPGE : Reda Slaoui Année scolaire : 2023/2024
Python : Correction TP1
Exercice 1 :
1 n1 = i n t ( i n p u t ( " E n t r e r un p r e m i e r nombre : " ) )
2 n2 = i n t ( i n p u t ( " E n t r e r un deuxieme nombre : " ) )
3 n3 = i n t ( i n p u t ( " E n t r e r un t r o i s i e m e nombre : " ) )
4 s = n1+n2+n3
5 m = s /3
6 p = n1∗n2∗n3
7 p r i n t ( "Somme : " , s )
8 p r i n t ( " Produit : " ,p)
9 p r i n t ( " Moyenne : " ,m)
Exercice 2 :
1 n = i n t ( i n p u t ( " E n t r e r un nombre p o s i t i f : " ) )
2 racine = n∗∗(1/2)
3 c a r r e = n∗∗2
4 print ( " racine : " , racine )
5 print ( " carre : " , carre )
Exercice 3 :
1 a = i n t ( i n p u t ( " E n t r e r un p r e m i e r nombre : " ) )
2 b = i n t ( i n p u t ( " E n t r e r un deuxieme nombre : " ) )
3 q = a //b
4 r = a%b
5 p r i n t ( " R e s u l t a t : " , a , "=" , b , " x " , q , "+" , r )
Exercice 4 :
1 C = f l o a t ( i n p u t ( " E n t r e r l a t e m p e r a t u r e en c e l c i u s : " ) )
2 K = C + 273.15
3 F = ( 9 / 5 ) ∗C+32
4 p r i n t ( " K e l v i n : " ,K)
5 p r i n t ( " F a h r e n h e i t : " ,F)
1
Exercice 5 :
1 xa = f l o a t ( i n p u t ( " E n t r e r l ’ a b s c i s s e du point A: "))
2 ya = f l o a t ( i n p u t ( " E n t r e r l ’ ordonnee du point A: "))
3 xb = f l o a t ( i n p u t ( " E n t r e r l ’ a b s c i s s e du point B: "))
4 yb = f l o a t ( i n p u t ( " E n t r e r l ’ ordonnee du point B: "))
5 d = ( ( xa−xb ) ∗∗2+(ya−yb ) ∗ ∗ 2 ) ∗ ∗ 0 . 5
6 p r i n t ( " La d i s t a n c e e n t r e A e t B e s t : " ,d)
Exercice 6 :
1 m i l l e = f l o a t ( i n p u t ( " E n t r e r l a d i s t a n c e en m i l l e : " ) )
2 metre = m i l l e ∗ 1 6 0 9 . 3 4 4
3 p r i n t ( " La d i s t a n c e en metre e s t : " , metre )
Exercice 7 :
1 A = i n t ( i n p u t ( " E n t r e r l a v a l e u r de A ( s t r i c t e m e n t p o s i t i f ) : " ) )
2 B = i n t ( i n p u t ( " E n t r e r l a v a l e u r de B : " ) )
3 x = −B/A
4 p r i n t ( " La s o l u t i o n de " ,A, " x+" ,B, "=0 e s t x = " , x )
Exercice 8 :
1 ht = f l o a t ( i n p u t ( " E n t r e r l e p r i x h o r s t a x e s : " ) )
2 n = i n t ( i n p u t ( " E n t r e r l e nombre d ’ a r t i c l e s : " ) )
3 tva = f l o a t ( i n p u t ( " E n t r e r l e taux de tva : " ) )
4 t t c = n∗ ht ∗ ( tva +1)
5 p r i n t ( " Le p r i x TTC e s t : " , t t c )
Exercice 9 :
1 #1 e r e s o l u t i o n
2 X = i n t ( i n p u t ( " E n t r e r un p r e m i e r nombre : " ) )
3 Y = i n t ( i n p u t ( " E n t r e r un deuxieme nombre : " ) )
4 p r i n t ( " Avant l a permution X=" ,X, " e t Y=" ,Y)
5 Z = X
6 X = Y
7 Y = Z
8 p r i n t ( " Apres l a permution X=" ,X, " e t Y=" ,Y)
1 #2eme s o l u t i o n
2 X = i n t ( i n p u t ( " E n t r e r un p r e m i e r nombre : " ) )
3 Y = i n t ( i n p u t ( " E n t r e r un deuxieme nombre : " ) )
4 p r i n t ( " Avant l a permution X=" ,X, " e t Y=" ,Y)
5 X,Y = Y,X
6 p r i n t ( " Apres l a permution X=" ,X, " e t Y=" ,Y)