Wpis z mikrobloga

Klikam sobie bootcampa na Udemy: Master Python by building 100 projects in 100 days. Learn data science, automation, build websites, games and apps!

Jestem na Day 15: Coffee Machine Project i kod ma spełnić takie requirements:

Coffee Machine Program Requirements
1. Prompt user by asking “ What would you like? (espresso/latte/cappuccino): ”
a. Check the user’s input to decide what to do next.
b. The prompt should show every time action has completed, e.g. once the drink is
dispensed. The prompt should show again to serve the next customer.
2. Turn off the Coffee Machine by entering “ off ” to the prompt.
a. For maintainers of the coffee machine, they can use “off” as the secret word to turn off
the machine. Your code should end execution when this happens.
3. Print report.
a. When the user enters “report” to the prompt, a report should be generated that shows
the current resource values. e.g.
Water: 100ml
Milk: 50ml
Coffee: 76g
Money: $2.5
4. Check resources sufficient?
a. When the user chooses a drink, the program should check if there are enough
resources to make that drink.
b. E.g. if Latte requires 200ml water but there is only 100ml left in the machine. It should
not continue to make the drink but print: “ Sorry there is not enough water. ”
c. The same should happen if another resource is depleted, e.g. milk or coffee.
5. Process coins.
a. If there are sufficient resources to make the drink selected, then the program should
prompt the user to insert coins.
b. Remember that quarters = $0.25, dimes = $0.10, nickles = $0.05, pennies = $0.01
c. Calculate the monetary value of the coins inserted. E.g. 1 quarter, 2 dimes, 1 nickel, 2
pennies = 0.25 + 0.1 x 2 + 0.05 + 0.01 x 2 = $0.52
6. Check transaction successful?
a. Check that the user has inserted enough money to purchase the drink they selected.
E.g Latte cost $2.50, but they only inserted $0.52 then after counting the coins the
program should say “ Sorry that's not enough money. Money refunded. ”.
b. But if the user has inserted enough money, then the cost of the drink gets added to the
machine as the profit and this will be reflected the next time “report” is triggered. E.g.
Water: 100ml
Milk: 50ml
Coffee: 76g
Money: $2.5
c. If the user has inserted too much money, the machine should offer change.

Ofc nie limitowałem inputu, także łatwo wykrzaczyć, ale nie o to chodzi.

Zroastowałby ktoś mój kod pls? Co można poprawić, co nie tak, etc? Wydaje się, że śmiga jeśli input damy 'dobrze' tak na chłopski rozum. Ofc dopiero się uczę, thx!

Kod: https://pastebin.com/YLJSX8BP

#python
  • 7
  • Odpowiedz
  • Otrzymuj powiadomienia
    o nowych komentarzach

@zwei: Jeśłi chodzi o get(), to jeszcze nie wprowadzili tego w kursie, tu jest kod prowadzącego: https://pastebin.com/VF5EUkww - ale już obczaiłem i postaram się używać going forward, dzięki!

Co do wielkości, że jedno wielkimi, drugie małymi - babka mówiła, że stałe wartości CAPSEM, a wartości, które się zmieniają - w naszym przypadku resources - małymi. Czy poza kursem też ludzie się tego trzymają, czy niet?

Co do reszty, thx!
  • Odpowiedz
@zwei: thx, właśnie sprawdziłem, to prowadzący też ma funkcję i z printem i z returnem... chyba po prostu ten poziom jeszcze, że sporo konceptów wprowadza, ale nie wszystko na tip-top wyśrubowane, mam nadzieję, że później będzie clean code.
  • Odpowiedz
via Wykop Mobilny (Android)
  • 1
@MichaelWhite2137: jasne, nikt nie będzie pisał ultra clean code'u w takich prostych zadankach, też pomija się kwestie poprawności inputow, itd. Tak naprawdę to nie ma jeszcze za bardzo czego roastowac na tym poziomie :) za miesiac lub dwa już pewnie coś się znajdzie
  • Odpowiedz