python写猜数字

import random

def guess_number_game():

number_to_guess = random.randint(1, 100)

attempts = 0

print("欢迎来到猜数字游戏!我想了一个1到100之间的数,你有5次机会猜出它.")

while True:

user_guess = int(input("请输入你的猜测: "))

attempts += 1

if user_guess < number_to_guess:

print("太小了,再试一次!")

elif user_guess > number_to_guess:

print("太大了,再试试!")

else:

print(f"恭喜你,猜对了!你用了{attempts}次尝试.")

break

guess_number_game()

相关推荐
用户2705077725241 小时前
MCP 最小 Server 实测:3 个 JSON-RPC 报错与修法
前端
SL_staff1 小时前
从配置失效到逻辑复用:JVS-Logic 如何构建可治理的业务编排中枢
java·spring·产品
用户499335025071 小时前
一人VIP账号多人共用:Web 代理里的会话共享怎么实现
前端
特立独行的猫A1 小时前
一份 Markdown 发十个平台:cspub 一稿多投
java·后端·python
用户老李1 小时前
无线电自学教程 05:第一台收音机——从矿石机到 SDR
前端
IPIPD1 小时前
Node.js请求遇到503怎么重试?先解析Retry-After,再做有上限退避
前端
葡萄城技术团队1 小时前
dsh-spreadjs-editor 的集成链路:把 SpreadJS Designer 嵌进 Agent 工作台
前端
深蓝AI1 小时前
HTTPX 超时 1 秒,接口为何还能跑 2.4 秒?
python
CyrusYiVPP1 小时前
哪个用户会再来买?RFM模型+plotly画出用户分层,数据分析实战第2期
人工智能·python
文丑颜不良啊2 小时前
LeetCode1961~1980题目解析
java·leetcode