desislava_topuzakova

06. Cake

Apr 4th, 2021
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. # брой на парчетата = лице на тортата = дължина * ширината
  2. # повтаряме: 1. прочитаме колко парчета са взети
  3.             # 2. намаляме броя на парчетата в тортата с взетите
  4.             # 3. проверка дали имаме още торта
  5. # command -> число под формата на текст ("10") или "STOP"
  6. # stop: command == "STOP"
  7. # continue: command != "STOP"
  8.  
  9. width = int(input())
  10. length = int(input())
  11. count_pieces = width * length
  12.  
  13. command = input()
  14. while command != "STOP":
  15.     # command = "3"; има число под формата на текст -> "3" -> число 3
  16.     count_taken_pieces = int(command)
  17.     count_pieces -= count_taken_pieces
  18.     if count_pieces < 0:
  19.         print(f'No more cake left! You need {abs(count_pieces)} pieces more.')
  20.         break
  21.     command = input()
  22. else: # command == "STOP"
  23.     print(f'{count_pieces} pieces are left.')
Advertisement
Add Comment
Please, Sign In to add comment