我在Python进行循环时遇到问题
因此,我正在制作一个需要选择一个数字的程序(例如10),然后添加一个循环,每次都会在我的号码中添加一个单元。我已经尝试过:
while true :
num = 10
num += 1
print(num)
您能帮我吗?谢谢。
so I'm making a program that needs to pick a number (like 10) then add a loop that adds one unit to my number Everytime. I have tried this :
while true :
num = 10
num += 1
print(num)
can you help me on this? thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的示例不起作用,因为您每次都将其重置为10。
您必须这样做:
请注意,true是无效的,在Python中,您使用true。
另请注意,Python基于Whitespace,因此您将在if语句或循环中永不使用(bool)。这只是浪费空间添加()
Your example won’t work because you are resetting it to 10 every time.
You have to do so something like this:
Note that true is invalid and in python you use True.
Also note that python is based on whitespace so you will Never use (bool) in a if statement or a loop. It is just a waste of space to add ()
尝试做
Try doing