from random import randint
aList = [1,2,3] # 1-石头,2-剪刀,3-布
bList = ['','石头','剪刀','布']
while True:
computer = aList[randint(0,2)] #电脑模拟出拳
player = int(input("玩家输入: ")) #玩家出拳
if computer == player:
print ("平局\t 玩家输入{}\t电脑输入{}".format(bList[player],bList[computer]))
continue #平局就重新开始
elif computer -player == -1 or computer - player == 2:#石头-剪刀;剪刀-布;布-石头为电脑赢
print ("电脑赢\t 玩家输入{}\t电脑输入{}".format(bList[player],bList[computer]))
break
else:#其余情况玩家赢
print ('玩家赢\t 玩家输入{}\t电脑输入{}'.format(bList[player],bList[computer]))
break
网友评论