SHARE
TWEET

While Loop Exercise - Cake

chris_ton May 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. width = int(input())
  2. length = int(input())
  3.  
  4. cake_area = width * length
  5. all_pieces = 0
  6.  
  7. while cake_area > all_pieces:
  8.     pieces = input()
  9.     if pieces == "STOP":
  10.         pieces_left = cake_area - all_pieces
  11.         print(f"{pieces_left} pieces are left.")
  12.         break
  13.     else:
  14.         all_pieces += int(pieces)
  15.         if cake_area - int(all_pieces) <= 0:
  16.             print(f"No more cake left! You need {abs(cake_area - int(all_pieces))} pieces more.")            
  17.         else:
  18.             continue
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top