代码展示
import random
choices = ['石头','布','剪刀']
print('石头剪刀布游戏!')
player = input('你要出石头呢,还是剪刀呢,还是布?(如输入“退出”,可退出游戏)')
while (player != '退出'):
computer = random.choice(choices)
print((((('你出了' + player) + ',电脑出了') + computer) + '...'))
if (player == computer) :
print("平局!")
elif (player == '石头') :
if computer == "剪刀":
print("你赢了!")
else:
print("电脑赢了!")
elif (player == '布') :
if computer == "石头":
print("你赢了")
else:
print("电脑赢了!")
elif (player == '剪刀') :
if computer == "布":
print("你赢了")
else:
print("电脑赢了!")
else :
print("出错了哦!只能出“石头”“剪刀”或“布”!")
print('石头剪刀布游戏!')
player = input('你要出石头呢,还是剪刀呢,还是布?(如输入“退出”,可退出游戏)')
|