gpt4 book ai didi

python - 记录while循环运行了多少次? - Python

转载 作者:行者123 更新时间:2023-11-28 19:34:13 24 4
gpt4 key购买 nike

想象一下:

你有一个 while 循环

您想知道它运行了多少次

你应该做什么???

现在我听到你说,上下文是什么?

上下文:我正在用 Python 编写这个程序,它会想到 1 到 100 之间的一个数字,你会猜到它。猜测参与了一个 while 循环(请看下面的代码),但我需要知道进行了多少次猜测。

所以,这就是我需要的:

print("It took you " + number_of_guesses + " guesses to get this correct.")

这是 Gist 的完整代码:https://gist.github.com/anonymous/1d33c9ace3f67642ac09

请记住:我使用的是 Python 3x

提前致谢

最佳答案

count = 0

while x != y::
count +=1 # variable will increment every loop iteration
# your code


print count

关于python - 记录while循环运行了多少次? - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20255372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com