python三局两胜游戏

复制代码
分为以下步骤实现这个功能
1、猜拳
2、机器产生数值
3、人去猜数字,定义剪刀石头布
4、控制机器产生,123

程序运行的时候可能会出现一点玄学问题,就是,提示n+=1这一行不符合pep8然后报错,不用管,运行就可以,没有这一行就会进入死循环

python 复制代码
#三局两胜游戏
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('平局')
相关推荐
timeDifference₇2 小时前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu2 小时前
python:DecisionTree
开发语言·后端·python·算法
怒放的生命19914 小时前
代码知识库 RAG 问答系统 —— 从 0 到 1 实现教程
python·状态模式·fastapi·全栈开发·ai agent应用开发
geovindu4 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
fengkai45455 小时前
Python运维
运维·python·监控·psutil·ipy
Fancy.7615 小时前
:Python条件与循环语句学习总结
python
apcipot_rain5 小时前
某游戏公司C++游开实习 机试复盘
c++·游戏
北城笑笑6 小时前
Vue 112 ,下篇:前端 dist 还原成 Vue3 + Vite 项目( krpano 全景接入与页面适配实战,Vue2 → Vue3 )
前端·javascript·vue.js·3d·前端框架·vue·webgl
我叫黑大帅6 小时前
搜“张三”把备注也带出来了?不用加高级筛选,如何让一个搜索框实现「选项直达」!
前端·javascript·面试
Wellijohn7 小时前
Python 容器选型实测:list.insert(0) 慢 925 倍,in 慢 6000 倍
python