Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # И так сравниваем мы значения слева со значениями сверху. Например,
- # камень и камень - ничья (-1), камень и ножницы - побеждает камень (1),
- # камень и бумага - проигрыш: бумага накрывает камень (0).
- #
- # | | Камень | Ножницы | Бумага |
- # |---------+---------+---------+---------|
- # | Камень | -1 | 1 | 0 |
- # | Ножницы | 0 | -1 | 1 |
- # | Бумага | 1 | 0 | -1 |
- import random
- STONE = 'stone'
- SCISSORS = 'scissors'
- PAPER = 'paper'
- def compare(a, b):
- # Первый ряд таблицы
- if a == STONE and b == SCISSORS:
- return 1
- if a == STONE and b == PAPER:
- return 0
- # Второй
- if a == SCISSORS and b == STONE:
- return 0
- if a == SCISSORS and b == PAPER:
- return 1
- # Третий
- if a == PAPER and b == STONE:
- return 1
- if a == PAPER and b == SCISSORS:
- return 0
- assert a == b
- return -1
- items = [STONE, SCISSORS, PAPER]
- while 1:
- a = input('Choose your item: "paper", "stone" or "scissors": ')
- a = a.lower()
- if a not in items:
- print("Иди нахуй я так не играю!")
- continue
- b = random.choice(items)
- r = compare(a, b)
- print("{} vs {}: {}".format(
- a, b, {-1: "ничья", 0: "проиграл", 1: "выиграл"}[r]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement