Skip to content
Extraits de code Groupes Projets
Valider 0f6bae0e rédigé par Martin Delcourt's avatar Martin Delcourt
Parcourir les fichiers

Added Chapter_2

parent 2bec9e13
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
n_lines = int(input("Combien de lignes desirez-vous ?"))
#Méthode 1 : en multipliant des strings
line_id = 0
while line_id < n_lines:
print ((n_lines-line_id-1)*" "+(2*line_id+1)*"*")
line_id += 1
#Méthode 2 : Boucles imbriquées
line_id = 0
while line_id < n_lines:
col_id = 0
line_txt = ""
while col_id < n_lines + line_id:
if col_id < n_lines-line_id-1:
line_txt+=" "
else:
line_txt+="*"
col_id += 1
print(line_txt)
line_id += 1
u_m2 = 1
u_m1 = 1
print ("1 : 1")
print ("2 : 1")
i = 0
while i < 18:
u_m = u_m2+u_m1
u_m2 = u_m1
u_m1 = u_m
print ("{0} : {1}".format(i+2,u_m))
i += 1
import math
nombre = int(input("Entrez un nombre : "))
#On va utiliser la méthode brute-force...
div_candidat = 2
est_premier = True
while div_candidat <= math.sqrt(nombre):
division = nombre/div_candidat
if division == int(division):
est_premier = False
print("{0} n'est pas premier (il est divisible par {1})".format(nombre, div_candidat))
break
div_candidat += 1
if nombre == 1:
print ("1 n'est pas premier (il n'a qu'un seul diviseur)")
elif est_premier:
print ("{0} est premier !".format(nombre))
import math
#Toujours en brute-force
n_premiers = 0
nombre = 2
while n_premiers <= 1000:
div_candidat = 2
est_premier = True
while div_candidat <= math.sqrt(nombre):
division = nombre/div_candidat
if division == int(division):
est_premier = False
break
div_candidat += 1
if est_premier:
n_premiers += 1
print ("{0}/1000 : {1}".format(n_premiers,nombre))
nombre += 1
import math
step = 1
min_step = 1e-10
x = 0
while step >= min_step:
while math.exp(-0.5*x*x) > 0:
x += step
x -=step
step/=10
print ("Le nombre le plus petit est : {0}".format(math.exp(-0.5*x*x)))
print ("Vient de e^(-0.5*x**2) avec x = {0}".format(x))
n_player = int(input("Combien de joueurs participent ? "))
n_rounds = int(input("Combien de tours de jeu ? "))
n_played = 0
while n_played < n_rounds:
n_played += 1
to_say = ""
if n_played % 5 == 0:
to_say+="ding-ding "
if n_played % 7 == 0:
to_say+="bottle "
if to_say=="":
to_say=str(n_played)
to_say = "Joueur {0} : {1}".format(n_played%n_player,to_say)
print(to_say)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter