Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- items = ['камень',
- 'ножницы',
- 'бумага',
- ]
- won_lost = {'камень': {'ножницы': 'won',
- 'бумага': 'lost',
- 'камень': 'tie'
- },
- 'ножницы': {'камень': 'lost',
- 'бумага': 'won',
- 'ножницы': 'tie'
- },
- 'бумага': {'камень': 'won',
- 'ножницы': 'lost',
- 'бумага': 'tie'}
- }
- def choose_item(items):
- chosen_item = random.choice(items)
- return chosen_item
- def compare_choice(choice1, choice2):
- result = won_lost[choice1][choice2]
- return result
- def output_results():
- choice1 = choose_item(items)
- choice2 = choose_item(items)
- result = compare_choice(choice1, choice2)
- return f'{choice1} {result} {choice2}'
- if __name__ == '__main__':
- for i in range(5):
- print(output_results())
- assert compare_choice('бумага', 'бумага') == 'tie'
- assert compare_choice('камень', 'бумага') == 'lost'
- assert compare_choice('бумага', 'камень') == 'won'
Advertisement
Add Comment
Please, Sign In to add comment