From b4200046bb9d67e368a2d263aa56a201a73993e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= Date: Fri, 27 Mar 2026 17:16:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E6=8A=95=E7=A8=BF]=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC:=20guess=5Fnumber=20=E2=80=94=20by=20Yahoo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripts/games/guess_number_mn8otc34.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 script_library/scripts/games/guess_number_mn8otc34.py diff --git a/script_library/scripts/games/guess_number_mn8otc34.py b/script_library/scripts/games/guess_number_mn8otc34.py new file mode 100644 index 0000000..5798088 --- /dev/null +++ b/script_library/scripts/games/guess_number_mn8otc34.py @@ -0,0 +1,116 @@ +import random + +def guess_number_game(): + """ + 猜数字游戏 + 随机生成1-100的整数,玩家猜测直到猜对为止 + """ + # 生成随机数 + secret_number = random.randint(1, 100) + attempts = 0 + guess_history = [] # 记录猜测历史 + + print("🎮 欢迎来到猜数字游戏!") + print("我已经想好了一个1到100之间的整数。") + print("试着猜猜看是多少吧!") + print("提示:输入 'q' 可以退出游戏") + print("-" * 40) + + while True: + try: + # 获取玩家输入 + guess_input = input(f"第{attempts+1}次猜测(1-100):") + + # 检查是否要退出 + if guess_input.lower() in ['q', 'quit', 'exit', '退出']: + print(f"\n👋 游戏已退出。正确答案是 {secret_number}") + print(f"你猜了 {attempts} 次,猜测历史:{guess_history}") + return False + + guess = int(guess_input) + + # 验证输入范围 + if guess < 1 or guess > 100: + print("⚠️ 请输入1到100之间的数字!") + continue + + attempts += 1 + guess_history.append(guess) + + # 判断猜测结果 + if guess < secret_number: + print("🔽 小了!再试试看。") + elif guess > secret_number: + print("🔼 大了!再试试看。") + else: + print(f"\n🎉 恭喜你!猜对了!") + print(f"🎯 正确答案是:{secret_number}") + print(f"📊 你总共猜了 {attempts} 次") + print(f"📝 猜测历史:{guess_history}") + + # 根据尝试次数给出评价 + if attempts == 1: + print("🌟 太厉害了!一次就猜中!") + elif attempts <= 5: + print("👍 很棒!只用了很少的次数!") + elif attempts <= 10: + print("👌 不错!表现很好!") + else: + print("💪 继续努力,下次会更好!") + + return True + + except ValueError: + print("❌ 请输入有效的数字!或者输入 q 退出游戏") + except KeyboardInterrupt: + print("\n\n👋 游戏已退出。") + return False + +def show_instructions(): + """显示游戏说明""" + print("\n📖 游戏说明:") + print("1. 我会随机生成一个1-100之间的整数") + print("2. 你需要猜测这个数字是多少") + print("3. 每次猜测后,我会告诉你'大了'或'小了'") + print("4. 继续猜测直到猜对为止") + print("5. 游戏会记录你猜的次数") + print("6. 输入 'q' 可以随时退出游戏") + print("-" * 40) + +def main(): + """主函数,控制游戏流程""" + print("=" * 50) + print(" 猜数字游戏 v1.0") + print("=" * 50) + + show_instructions() + + total_games = 0 + total_attempts = 0 + best_score = float('inf') # 最佳成绩(最少尝试次数) + + while True: + total_games += 1 + print(f"\n🎲 第 {total_games} 局游戏开始!") + + # 玩一局游戏 + game_completed = guess_number_game() + + # 询问是否再玩一次 + print("\n" + "=" * 40) + play_again = input("想再玩一次吗?(y/n): ").lower() + + if play_again not in ['y', 'yes', '是', '好的']: + # 显示统计信息 + print("\n📈 游戏统计:") + print(f" 总游戏局数:{total_games}") + if total_games > 0 and total_attempts > 0: + print(f" 平均尝试次数:{total_attempts/total_games:.1f}") + if best_score < float('inf'): + print(f" 最佳成绩:{best_score} 次") + print("\n谢谢游玩!再见!👋") + break + print("\n" + "=" * 40) + +if __name__ == "__main__": + main() \ No newline at end of file From 17867c00f10f350ae2b43609d1139ad471fae795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= Date: Fri, 27 Mar 2026 17:16:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E6=8A=95=E7=A8=BF]=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20index.json:=20=E6=B7=BB=E5=8A=A0=20guess=5Fnumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script_library/index.json | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/script_library/index.json b/script_library/index.json index 6935041..753091b 100644 --- a/script_library/index.json +++ b/script_library/index.json @@ -1,7 +1,7 @@ { "format_version": 1, - "data_version": 28, - "updated": "2026-03-26T17:07:22Z", + "data_version": 29, + "updated": "2026-03-27T09:16:55.631Z", "announcement": null, "categories": [ { @@ -728,6 +728,29 @@ "updated": null, "status": "active", "lines": 471 + }, + { + "id": "guess_number_mn8otc34", + "name": "guess_number", + "name_en": "guess_number", + "desc": "猜数字", + "desc_en": "猜数字", + "category": "games", + "file": "scripts/games/guess_number_mn8otc34.py", + "thumbnail": null, + "version": 1, + "file_type": "py", + "author": "Yahoo", + "author_en": "Yahoo", + "tags": [ + "community" + ], + "requires": [], + "min_app_version": "1.5.0", + "added": "2026-03-27", + "updated": null, + "status": "active", + "lines": 116 } ] }