计数器 = 1 而计数器 <= 3: print(f"Hello, {user_name}! This is greeting number {counter}.") counter = 1 print("End of program.")

问题描述 投票:0回答:1

我需要使用计数器循环打印我的语句三次,因此为什么它不能产生准确的结果?有人可以帮助解决这个错误吗?该应用程序是用 Python 编写的。计数器循环有错误吗?

python python-3.x error-handling counter
1个回答
0
投票

好吧...,你只是忘了增加计数器😕 在您的代码中,您只是重置

counter
变量而不是递增它。

counter = 1
while counter <= 3:
    print(f"Hello, {user_name}! This is greeting number {counter}.")
    counter += 1

print("End of program.")
© www.soinside.com 2019 - 2024. All rights reserved.