石头剪刀布的Python代码简单编写希望喜欢:
import random
var = 1
while var ==1 : #表达式永远为真
player_input = input("请输入(0.剪刀,1,石头,2布:)")
player=int(player_input)
computer = random.randint(0,2)
if( player==0 and computer ==2 )or (player == 1 and computer == 0) \
or (player == 2 and computer == 1 ):
print("电脑出的是%s,恭喜,你赢了!"%computer)
elif (player == 1 and computer == 1) or (player == 0 and computer == 0)\
or (player == 2 and computer == 2):
print("电脑出的是%s,打成平局!"%computer)
else :
print("电脑出的是%s,不好意思,你输了!"%computer)