import random
you = input('请选择你出哪个(石头/剪刀/布,退出请输入q):')
computer = random.choice(['石头','剪刀','布'])
you_win = 0
com_win = 0
while you != 'q':
if you == computer:
print('打平 ','你和电脑的比分为%d:%d'%(you_win,com_win))
elif you == '石头':
if computer == '剪刀':
you_win+=1
print('赢了一次 ' , '你和电脑的比分为%d:%d' % (you_win, com_win))
else:
com_win+=1
print('输了一次 ' , '你和电脑的比分为%d:%d' % (you_win, com_win))
elif you == '剪刀':
if computer == '布':
you_win += 1
print('赢了一次 ' , '你和电脑的比分为%d:%d' % (you_win, com_win))
else:
com_win += 1
print('输了一次 ' , '你和电脑的比分为%d:%d' % (you_win, com_win))
else:
if computer == '石头':
you_win += 1
print('赢了一次 ' , '你和电脑的比分为%d:%d' % (you_win, com_win))
else:
com_win += 1
print('输了一次 ' , '你和电脑的比分为%d:%d' % (you_win, com_win))
you = input('请选择你出哪个(石头/剪刀/布,退出请输入q):')
computer = random.choice(['石头', '剪刀', '布'])
print('你和电脑的比分最终为%d:%d' % (you_win, com_win))
if you_win >com_win:
print('恭喜你战胜了电脑!')
else:
print('可惜你没有赢')
|