Advertisement
tod36

03. Vacation from Loops - Part 2 - Exercise

Feb 11th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. trip_money = float(input())
  2. real_money = float(input())
  3. saved_money = 0
  4. day_numb = 0
  5. spend_day = 0
  6.  
  7. while saved_money < trip_money:
  8.     command = input()
  9.     sum_of_command = float(input())
  10.     day_numb += 1
  11.     if command == "spend":
  12.         real_money -= sum_of_command
  13.         if real_money < 0:
  14.             real_money = 0
  15.         spend_day += 1
  16.     if command == "save":
  17.         spend_day = 0
  18.         real_money += sum_of_command
  19.         if real_money >= trip_money:
  20.             print(f"You saved the money for {day_numb} days.")
  21.             break
  22.     if spend_day == 5:
  23.         print("You can't save the money.")
  24.         print(spend_day)
  25.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement