【Python如何与电脑玩石头剪刀布游戏】

1、石头剪刀布Python代码如下:

python 复制代码
import random
while True:
    a = random.randint(0, 2)
    b = int(input("请输入一个数字(0=石头, 1=剪刀, 2=布): "))
    c = ['石头', '剪刀', '布']
    if b != 0 and b != 1 and b != 2:
        print("傻子,你出错了,请输入数字0或1或2!!!")
    elif a == b:
        print("电脑出了:{}\n你出了:{}\n平手\n自动开启下一局:".format(c[a], c[b]))
        continue
    elif a == 0 and b == 2 or a == 1 and b == 0 or a == 2 and b == 1:
        print("电脑出了:{}\n你出了:{}\n你赢了!".format(c[a], c[b]))
        break
    else:
        print("电脑出了:{}\n你出了:{}\n你输了".format(c[a], c[b]))
        break

2、运行结果:

相关推荐
aqi001 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵3 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf4 小时前
Agent 流程编排
后端·python·agent
copyer_xyf4 小时前
Agent RAG
后端·python·agent
copyer_xyf4 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf5 小时前
Agent 记忆管理
后端·python·agent
星云穿梭20 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵20 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
黄忠1 天前
大模型之LangGraph技术体系
python·llm