Advertisement
bl00dt3ars

05. Hot Potato

Aug 19th, 2021 (edited)
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. """ Hot Potato is a game in which children form a circle and start tossing a hot potato. The counting starts with the
  2. first kid. Every nth toss the child who is holding the potato leaves the game. When a kid leaves the game, it passes
  3. the potato to the next kid. This continues until there is only one kid left.
  4.    Create a program that simulates the game of Hot Potato. On the first line you will receive names of kids, separated
  5. by a single space. On the second line you will receive the nth toss (integer) in which a child leaves the game.
  6.    Print every kid which is removed from the circle in the format "Removed {kid}". In the end, print the only kid left
  7. in the format "Last is {kid}". """
  8.  
  9.  
  10. from collections import deque
  11.  
  12. kids = deque(input().split())
  13. toss = int(input())
  14.  
  15. while not len(kids) == 1:
  16.     for _ in range(toss - 1):
  17.         kids.append(kids.popleft())
  18.     print(f'Removed {kids.popleft()}')
  19.  
  20. print(f'Last is {kids[0]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement