Python basic tutorial to implement rock paper scissors game example
- 2020-04-02 13:23:54
- OfStack
Here are the rules. You and your opponent must make one of the following gestures at the same time: stone, scissors, paper
The following rule emerges, and the rule itself is a paradox.
(a) cloth wrapped in stone.
(b) stone breaking scissors,
In your computer version, the user enters her/his options, the computer finds a random option, and then you
To determine a winner or tie. Note: the best algorithm is to use as few if statements as possible
#coding:utf-8
import random
guess_list = [" stone "," scissors "," cloth "]
guize = [[" cloth "," stone "],[" stone "," scissors "],[" scissors "," cloth "]]
while True:
computer = random.choice(guess_list)
people = input(' Please enter: stone , scissors , cloth n').strip()
if people not in guess_list:
people = input(' Please re-enter: stone , scissors , cloth n').strip()
continue
if computer == people:
print(" Tie! Play again! ")
elif [computer,people] in guize :
print(" The computer wins! ")
else:
print(" To victory! ")
break