.
This commit is contained in:
32
bac1/q1/29sept/ex1-2.py
Normal file
32
bac1/q1/29sept/ex1-2.py
Normal file
@ -0,0 +1,32 @@
|
||||
def rendreMonnaie(prix, monnaie):
|
||||
x1, x2, x3, x4, x5 = monnaie # Chaques billets en entree (20, 10, 5, 2, 1)
|
||||
|
||||
given = (x1*20) + (x2*10) + (x3*5) + (x4*2) + (x5*1)
|
||||
|
||||
rest = given - prix
|
||||
if rest < 0:
|
||||
return f"vous n'avez pas assez d'argent. Il manque : {-rest}"
|
||||
|
||||
o1 = rest // 20
|
||||
rest = rest % 20
|
||||
|
||||
o2 = rest // 10
|
||||
rest = rest % 10
|
||||
|
||||
o3 = rest // 5
|
||||
rest = rest % 5
|
||||
|
||||
o4 = rest // 2
|
||||
rest = rest % 2
|
||||
|
||||
o5 = rest // 1
|
||||
rest = rest % 1
|
||||
|
||||
return o1, o2, o3, o4, o5
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
prix = int(input("quel est le prix :"))
|
||||
print("entrez maintenant les billets")
|
||||
mon = (int(input("20e:")),int(input("10e:")),int(input("5e:")),int(input("2e:")),int(input("1e:")))
|
||||
print(rendreMonnaie(prix, mon))
|
Reference in New Issue
Block a user