Advertisement
Guest User

Untitled

a guest
Jan 6th, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. from decimal import Decimal
  2.  
  3. available_money = Decimal(input())
  4. command = input()
  5.  
  6. while command != "mall.Enter":
  7.     command = input()
  8.  
  9. number_purchases = 0
  10.  
  11. while True:
  12.  
  13.     action = input()
  14.  
  15.     if action == "mall.Exit":
  16.         break
  17.  
  18.     for symbol in range(len(action)):
  19.  
  20.         if 65 <= ord(action[symbol]) <= 90:
  21.             cost_of_purchase = ord(action[symbol]) * Decimal(0.50)
  22.             if cost_of_purchase <= available_money:
  23.                 available_money -= cost_of_purchase
  24.                 number_purchases += 1
  25.  
  26.         elif 97 <= ord(action[symbol]) <= 122:
  27.             cost_of_purchase = ord(action[symbol]) * Decimal(0.30)
  28.             if cost_of_purchase <= available_money:
  29.                 available_money -= cost_of_purchase
  30.                 number_purchases += 1
  31.  
  32.         elif action[symbol] == "%":
  33.             if available_money != 0:
  34.                 available_money *= Decimal(0.50)
  35.                 number_purchases += 1
  36.  
  37.         elif action[symbol] == "*":
  38.             available_money += 10
  39.  
  40.         else:
  41.             cost_of_purchase = ord(action[symbol])
  42.             if cost_of_purchase <= available_money:
  43.                 available_money -= cost_of_purchase
  44.                 number_purchases += 1
  45.  
  46. if number_purchases == 0:
  47.     print(f"No purchases. Money left: {available_money:.2f} lv.")
  48. else:
  49.     print(f"{number_purchases} purchases. Money left: {available_money:.2f} lv.")
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement