Вы находитесь на странице: 1из 5

Un manuel de solutions

Une introduction pratique à la programmation


Python

[Brian Heinold,
Département de mathématiques et d'informatique
Université Mount St. Mary's]

Ingénieur. Reyhan Usman Dalhatu


Chapitre 1
Commencer

#1 : Imprimer un rectangle

imprimer ('*' * 19) #imprimer * 19x


imprimer ('*' * 19)
imprimer ('*' * 19)
imprimer ('*' * 19)

#2 : Imprimer un rectangle

imprimer ('*' * 19)


print ('* *') #prints * 2x avec un espace entre les deux
imprimer ('* *')
imprimer ('*' * 19)

#3 : Imprimer un triangle

imprimer ('*')
imprimer ('*' * 2)
imprimer ('*' * 3)
imprimer ('*' * 4)

#4 : Calcul simple

imprimer ((512 - 282)/(47,48 + 5))


#5 : Imprimer le carré d'un nombre

num = eval(input("Entrez un nombre : "))


print ("Le carré de", num, "est", num * num, '.', sep=' ')

#6 : Séquence de multiplication

x = eval(input("Entrez un nombre : "))


print (x, 2*x, 3*x, 4*x, 5*x, sep='---') #imprimer x, 2x, 3x, 4x et 5x

#7 : Convertisseur de kilogramme en livre

poids = eval(input('Entrez un poids en kg : '))


print('C'est-à-dire', poids * 2,2, 'livres.') #pour chaque kg, il y a 2,2 livres

#8 : Variable totale et moyenne

x = eval(input("Entrez une valeur x : "))


y = eval(input("Entrez une valeur y : "))
z = eval(input("Entrez une valeur z : "))
total = x + y + z #variable qui totalise xyz
moyenne = total / 3 #moyenne variable
print("Le total x, y, z est : ", total)
print("Moyenne : ", moyenne)
imprimer ()
#9 : Calculateur de pourboire

repas_prix = eval(input("Prix du repas : $"))


tip_percent = eval(input("Pourboire (%) que vous souhaitez laisser : "))
tip_amount = (tip_percent / 100) * (meal_price)
total_bill = (tip_amount) + (meal_price)
print ("Votre repas est : $", repas_prix, " et vous avez donné un
pourboire ", tip_percent, "% à : $", tip_amount, ".", sep = ")
print ("Votre facture totale est de : $", total_bill, sep = '')

Вам также может понравиться