Advertisement
Spocoman

01. Dishwasher

Dec 29th, 2021 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. Решение с for:
  2.  
  3. import sys
  4.  
  5. soupMl = int(input()) * 750
  6. dishes = 0
  7. pots = 0
  8.  
  9. for i in range(1, sys.maxsize):
  10.     command = input()
  11.     if command == 'End':
  12.         print('Detergent was enough!')
  13.         print(f'{dishes} dishes and {pots} pots were washed.')
  14.         print(f'Leftover detergent {soupMl} ml.')
  15.         break
  16.  
  17.     charge = int(command)
  18.     if i % 3 != 0:
  19.         dishes += charge
  20.         soupMl -= charge * 5
  21.     else:
  22.         pots += charge
  23.         soupMl -= charge * 15
  24.  
  25.     if soupMl < 0:
  26.         print(f'Not enough detergent, {abs(soupMl)} ml. more necessary!')
  27.         break
  28.  
  29. Решение с while:
  30.  
  31. soupMl = int(input()) * 750
  32. dishes = 0
  33. pots = 0
  34. count = 1
  35. command = input()
  36. while command != 'End':
  37.     charge = int(command)
  38.     if count % 3 != 0:
  39.         dishes += charge
  40.         soupMl -= charge * 5
  41.     else:
  42.         pots += charge
  43.         soupMl -= charge * 15
  44.  
  45.     if soupMl < 0:
  46.         break
  47.     command = input()
  48.     count += 1
  49.  
  50. if command == 'End':
  51.     print('Detergent was enough!')
  52.     print(f'{dishes} dishes and {pots} pots were washed.')
  53.     print(f'Leftover detergent {soupMl} ml.')
  54. else:
  55.     print(f'Not enough detergent, {abs(soupMl)} ml. more necessary!')
  56.  
  57. Решение с колекция и тернарен оператор:
  58.  
  59. info = {'soupMl': int(input()) * 750, 'dishes': 0, 'pots': 0, 'index': 1}
  60.  
  61. command = input()
  62. while command != 'End':
  63.     charge = int(command)
  64.     info['dishes' if info['index'] % 3 != 0 else 'pots'] += charge
  65.     info['soupMl'] -= charge * (5 if info['index'] % 3 != 0 else 15)
  66.     if info['soupMl'] < 0:
  67.         break
  68.     info['index'] += 1
  69.     command = input()
  70.  
  71. print(f'Not enough detergent, {abs(info["soupMl"])} ml. more necessary!' if info['soupMl'] < 0 else
  72.       f'Detergent was enough!\n{info["dishes"]} dishes and {info["pots"]} pots were washed.\n Leftover detergent {info["soupMl"]} ml.')
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement