Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Решение с for:
- import sys
- soupMl = int(input()) * 750
- dishes = 0
- pots = 0
- for i in range(1, sys.maxsize):
- command = input()
- if command == 'End':
- print('Detergent was enough!')
- print(f'{dishes} dishes and {pots} pots were washed.')
- print(f'Leftover detergent {soupMl} ml.')
- break
- charge = int(command)
- if i % 3 != 0:
- dishes += charge
- soupMl -= charge * 5
- else:
- pots += charge
- soupMl -= charge * 15
- if soupMl < 0:
- print(f'Not enough detergent, {abs(soupMl)} ml. more necessary!')
- break
- Решение с while:
- soupMl = int(input()) * 750
- dishes = 0
- pots = 0
- count = 1
- command = input()
- while command != 'End':
- charge = int(command)
- if count % 3 != 0:
- dishes += charge
- soupMl -= charge * 5
- else:
- pots += charge
- soupMl -= charge * 15
- if soupMl < 0:
- break
- command = input()
- count += 1
- if command == 'End':
- print('Detergent was enough!')
- print(f'{dishes} dishes and {pots} pots were washed.')
- print(f'Leftover detergent {soupMl} ml.')
- else:
- print(f'Not enough detergent, {abs(soupMl)} ml. more necessary!')
- Решение с колекция и тернарен оператор:
- info = {'soupMl': int(input()) * 750, 'dishes': 0, 'pots': 0, 'index': 1}
- command = input()
- while command != 'End':
- charge = int(command)
- info['dishes' if info['index'] % 3 != 0 else 'pots'] += charge
- info['soupMl'] -= charge * (5 if info['index'] % 3 != 0 else 15)
- if info['soupMl'] < 0:
- break
- info['index'] += 1
- command = input()
- print(f'Not enough detergent, {abs(info["soupMl"])} ml. more necessary!' if info['soupMl'] < 0 else
- f'Detergent was enough!\n{info["dishes"]} dishes and {info["pots"]} pots were washed.\n Leftover detergent {info["soupMl"]} ml.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement