Case study

advertisement
Write class CoffeMachine with parameters water, beans, milk and name. Implement it in a
Python code which performs following:
1. Receives input from a user regarding type of a coffee (espresso, machiato, and cappucino).
2. For espresso machine uses 7 beans of coffee and 5ml of water, for machiato machine uses
5 beans of coffee, 3 ml of milk and 3 ml of water and for machiato it uses 5 beans of
coffee 2 ml of milk and 1 ml of water.
3. After user make 7 coffies machine displays „empty tray“ message, after 1 l of water tank
is empty machine displays „water tank empty“ and after there are no more beans in
machine displays „no coffee, please add more“.
4. Machine also requires cleaning after 150 coffies made. Assume that machine accepts 1 kg
of coffee=850 beans.
5. Within this solution write also a functions which caluclae remaining/added number of
beans, water tank and milk.
6. Restrict adding of coffee, milk and water only if there is displayed one of the messages
above.
My solution:
again = "Yes"
beans = 850
milk = 1000
water = 1000
check = 0
while again == "Yes":
if check == 7:
print("Tank is empty.")
if check == 150:
print("Clean the tank.")
if beans < 7:
print("Refil coffee beans.")
beans = beans + int(input("What is the amount of coffee added? "))
break
elif milk < 3:
print("Add milk.")
milk = milk + int(input("What is the amount of milk added? "))
break
elif water < 5:
print("Add water.")
water = water + int(input("What is the amount of water added? "))
break
else:
coffee = int(input("Choose type of coffee: 1 = espresso 2 = machiato 3 = cappucino "))
if coffee == 1:
beans = beans - 7
water = water - 5
if coffee == 2:
beans = beans - 5
milk = milk - 3
water = water - 3
if coffee == 3:
beans = beans - 5
milk = milk - 2
water = water - 1
print("Remaining beans: ", beans)
print("Remaining milk: " , milk)
print("Remaining water: " , water)
check = check + 1
again = input("Would you like to make another cup of coffee? ")
Output:
Choose type of coffee: 1 = espresso 2 = machiato 3 = cappucino 2
Remaining beans: 845
Remaining milk: 997
Remaining water: 997
Would you like to make another cup of coffee?
Download