python - 我希望我的程序在 5x 试验结束时终止
问题描述
这是我的代码,一切似乎都正常,只有部分试用版不起作用。
counter = 1
max_attempt = 5
secrect_nu = 313
num = int(input("Guess my number: "))
while num != secrect_nu:
max_attempt = max_attempt - 1
print(emoji.emojize(":winking_face_with_tongue: :winking_face_with_tongue: \U0001F606"))
num = int(input(f"HHHHH! You stuck in my loop you've {max_attempt} left \nGuess my number: "))
if num >= max_attempt:
print("Game Over!")
break
counter += 1
# while num >= max_attempt:
#
# break
if num == secrect_nu:
print("==========================================")
print("Congrats, You've broken the chain of my loop. ")
print("You got my secrect number in your " + str(counter) + "th attempt.")
我想解决试用问题,如果用户超过 5 次试用,我希望程序停止
解决方案
这样做应该对你有用:
counter = 1
max_attempt = 5
secrect_nu = 313
num = int(input("Guess my number: "))
while num != secrect_nu:
max_attempt = max_attempt - 1
num = int(input(f"HHHHH! You stuck in my loop you've {max_attempt} left \nGuess my number: "))
if counter==4:
print("Game Over!")
break
counter += 1
if num == secrect_nu:
print("==========================================")
print("Congrats, You've broken the chain of my loop. ")
print("You got my secrect number in your " + str(counter) + "th attempt.")
它将每次检查是否counter
为 4 以及num
是否等于secrect_nu
。
推荐阅读
- google-apps-script - 永久限制或限制 Google Picker 返回的文件
- textures - Direct3D 为许多对象保留不同的纹理
- python - 我怎样才能灵活地计算 *a 项目?
- python - 如何为数据集中的每个类别创建唯一的条形图?
- c# - 在 ASP.NET Core 中使用 IActionResult 阐明 C# 接口概念
- apache - Google Analytics v4 的内容安全策略
- swiftui - 我究竟做错了什么?**JSON[27471:6916633] [] nw_protocol_get_quic_image_block_invoke dlopen libquic 失败**
- flutter - Flutter web如何获得全屏尺寸
- c - 输入大小超过 10 时 malloc 失败
- rust - Rust target-cpu=native 使 SIMD 执行速度变慢