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

Python Exercices

The document contains examples of using Python to solve various math and coding exercises. These include: 1. Calculating recipe ingredients for chocolate mousse based on a number of people. 2. Drawing a cube using the Turtle module by giving commands to turn and move the turtle. 3. Calculating coordinate points around a hexagon based on user input for the length of one side. 4. Taking user input of different numeric values and performing various math operations on them like addition, multiplication, division, exponents, etc. and printing the results.

Uploaded by

souhail
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
50 views4 pages

Python Exercices

The document contains examples of using Python to solve various math and coding exercises. These include: 1. Calculating recipe ingredients for chocolate mousse based on a number of people. 2. Drawing a cube using the Turtle module by giving commands to turn and move the turtle. 3. Calculating coordinate points around a hexagon based on user input for the length of one side. 4. Taking user input of different numeric values and performing various math operations on them like addition, multiplication, division, exponents, etc. and printing the results.

Uploaded by

souhail
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 4

1] EXERCICE : recette mousse au chocolat avec affectation et variable

n = 2
sucre_vanille = 1*n//4
chocolats_noir = 100*n//4
oeufs = 3*n//4

2] EXERCICE : (script recette mousse au chocolat avec input() et


print())

n = float(input("nombres de personnes : "))


sucre_vanille = 1*n//4
chocolats_noir = 100*n//4
oeufs = 3*n//4
print("sucre vanille :", sucre_vanille)
print("chocolats noir :", chocolats_noir)
print("oeufs :", oeufs)
nombres de personnes : 7
sucre vanille : 1.0
chocolats noir : 175.0
oeufs : 5.0

3] EXERCICE : dessiner un cube avec turtle (sans indication)

import turtle

turtle.color('black')
turtle.begin_fill()
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.end_fill()
turtle.color('red')
turtle.begin_fill()
turtle.left(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.end_fill()
turtle.color('green')
turtle.begin_fill()
turtle.right(60)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(60)
turtle.forward(100)
turtle.end_fill()

(avec indication angle 60°)

import turtle

turtle.color('black')
turtle.begin_fill()
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.end_fill()
turtle.color('red')
turtle.begin_fill()
turtle.left(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.right(60)
turtle.forward(100)
turtle.right(120)
turtle.forward(100)
turtle.end_fill()
turtle.color('green')
turtle.begin_fill()
turtle.right(60)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(60)
turtle.forward(100)
turtle.end_fill()

(amelioré avec t.goto)

import math as m
import turtle as t

t.color("blue")
t.begin_fill()
t.goto(100,0)
t.goto(m.cos(m.pi/3)*100,m.sin(m.pi/3)*100)
t.goto(m.cos(2*m.pi/3)*100,m.sin(2*m.pi/3)*100)
t.goto(0,0)
t.end_fill()
t.color("black")
t.begin_fill()
t.goto(m.cos(2*m.pi/-3)*100,m.sin(2*m.pi/-3)*100)
t.goto(m.cos(m.pi/-3)*100,m.sin(m.pi/-3)*100)
t.goto(100,0)
t.goto(0,0)
t.end_fill()
t.color("red")
t.begin_fill()
t.goto(m.cos(2*m.pi/3)*100,m.sin(2*m.pi/3)*100)
t.goto(-100,0)
t.goto(m.cos(2*m.pi/3)*100,-m.sin(2*m.pi/3)*100)
t.end_fill()

4] EXERCICE : 2.4

import math as m

n = float(input("entre une longeur :"))

a = (-m.cos(m.pi)*n,0.0)
b = (m.cos(m.pi/3)*n,m.sin(m.pi/3)*n)
c = (m.cos(2*m.pi/3)*n,m.sin(2*m.pi/3)*n)
d = (m.cos(3*m.pi/3)*n,m.sin(3*m.pi/3)*n)
e = (m.cos(4*m.pi/3)*n,m.sin(4*m.pi/3)*n)
f = (m.cos(5*m.pi/3)*n,m.sin(5*m.pi/3)*n)

print(a)
print(b)
print(c)
print(d)
print(e)
print(f)

(correction par moi-même)

import math as m

n = float(input())

a = (-m.cos(m.pi)*n,0.0)
b = (m.cos(m.pi/3)*n,m.sin(m.pi/3)*n)
c = (m.cos(2*m.pi/3)*n,m.sin(2*m.pi/3)*n)
d = (m.cos(3*m.pi/3)*n,m.sin(3*m.pi/3)*n)
e = (m.cos(4*m.pi/3)*n,m.sin(4*m.pi/3)*n)
f = (m.cos(5*m.pi/3)*n,m.sin(5*m.pi/3)*n)

coordonnee = [a,b,c,d,e,f]

for letter in coordonnee :


x,y = letter
print(x,y)

5] EXERCICE : 2.5
x = int(input())
y = int(input())
z = float(input())
t = float(input())

a = x - y
b = x + z
c = z + t
d = x * z
e = x / 2
f = x / (y+1)
g = (x+y)*z / (4*x)
h = x ** (-1/2)

liste = [a,b,c,d,e,f,g,h]

for number in liste:


print(number)

6] EXERCICE : 2.

You might also like