agel122

Untitled

Nov 18th, 2021
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import random
  2.  
  3. items = ['камень',
  4.          'ножницы',
  5.          'бумага',
  6.          ]
  7.  
  8. won_lost = {'камень': {'ножницы': 'won',
  9.                        'бумага': 'lost',
  10.                        'камень': 'tie'
  11.                        },
  12.             'ножницы': {'камень': 'lost',
  13.                         'бумага': 'won',
  14.                         'ножницы': 'tie'
  15.                         },
  16.             'бумага': {'камень': 'won',
  17.                        'ножницы': 'lost',
  18.                        'бумага': 'tie'}
  19.             }
  20.  
  21.  
  22. def choose_item(items):
  23.     chosen_item = random.choice(items)
  24.     return chosen_item
  25.  
  26.  
  27. def compare_choice(choice1, choice2):
  28.     result = won_lost[choice1][choice2]
  29.     return result
  30.  
  31.  
  32. def output_results():
  33.     choice1 = choose_item(items)
  34.     choice2 = choose_item(items)
  35.     result = compare_choice(choice1, choice2)
  36.     return f'{choice1} {result} {choice2}'
  37.  
  38.  
  39. if __name__ == '__main__':
  40.     for i in range(5):
  41.         print(output_results())
  42.  
  43.     assert compare_choice('бумага', 'бумага') == 'tie'
  44.     assert compare_choice('камень', 'бумага') == 'lost'
  45.     assert compare_choice('бумага', 'камень') == 'won'
Advertisement
Add Comment
Please, Sign In to add comment