Advertisement
Spocoman

Easter Eggs Battle

Feb 21st, 2022 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. first_player = int(input())
  2. second_player = int(input())
  3. command = input()
  4.  
  5. while command != 'End':
  6.  
  7.     if command == 'one':
  8.         second_player -= 1
  9.         if second_player == 0:
  10.             print(f'Player two is out of eggs. Player one has {first_player} eggs left.')
  11.             break
  12.  
  13.     elif command == 'two':
  14.         first_player -= 1
  15.         if first_player == 0:
  16.             print(f'Player one is out of eggs. Player two has {second_player} eggs left.')
  17.             break
  18.  
  19.     command = input()
  20.  
  21. if command == 'End':
  22.    print(f'Player one has {first_player} eggs left.\nPlayer two has {second_player} eggs left.')
  23.  
  24. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  25.  
  26. first_player = int(input())
  27. second_player = int(input())
  28.  
  29. while True:
  30.     command = input()
  31.     if command == 'End':
  32.         print(f'Player one has {first_player} eggs left.\nPlayer two has {second_player} eggs left.')
  33.         break
  34.     else:
  35.         first_player -= 1 if command == 'two' else 0
  36.         second_player -= 1 if command == 'one' else 0
  37.         if first_player == 0 or second_player == 0:
  38.             print(f'Player {"one" if first_player == 0 else "two"} is out of eggs. '
  39.                   f'Player {"two" if first_player == 0 else "one"} has {second_player if first_player == 0 else first_player} eggs left.')
  40.             break
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement