想象一下:
你有一个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。
提前感谢。