分为以下步骤实现这个功能
1、猜拳
2、机器产生数值
3、人去猜数字,定义剪刀石头布
4、控制机器产生,123
程序运行的时候可能会出现一点玄学问题,就是,提示n+=1这一行不符合pep8然后报错,不用管,运行就可以,没有这一行就会进入死循环
#三局两胜游戏
import random
#计数 people count,machine count
p_count = 0
m_count = 0
n =1
while n<= 3:
#猜拳
# 机器产生数值
#人去猜数字,定义剪刀石头布
#控制机器产生,012
ran = random.randint(0,2)
guess = int(input('请输入1、剪刀、2、石头、3、布\n'))
if(guess == 0 and ran == 2) or (guess ==1 and ran == 0) or (guess == 2 and ran ==1):
print('~~~~~我赢了~~~~~')
p_count += 1
elif(ran == 0 and guess == 2) or (ran == 1 and guess == 0) and (ran ==2 and guess ==1):
print('~~~~~机器赢了~~~~')
m_count += 1
else:
print('平局')
n += 1
#胜负比较
if p_count < m_count:
print('最后机器获胜')
elif p_count > m_count:
print('最后人获胜')
else:
print('平局')