def print_range(start, end):
# Loop through the numbers from start to end
n = start
while n <= end:
print(n)
print_range(1, 5) # Should print 1 2 3 4 5 (each number on its own line)
def print_range(start, end):
# Loop through the numbers from start to end
n = start
while n <= end:
print(n)
n+=1
print_range(1, 5) # Should print 1 2 3 4 5 (each number on its own line)
def print_range(start, end):
# Loop through the numbers from start to end
n = start
while n <= end:
print(n)
n += 1
print_range(1, 5) # Should print 1 2 3 4 5 (each number on its own line)
循环变量
n
在while
循环中没有更改,因此它始终保持等于start
,因此它(可能)永远小于end
将
n = n+1
添加到循环中您从不增加
n
,因此代码会继续打印1
将代码更改为:
你真的应该给你的代码加上标记。 在代码的开头和结尾使用“`”,使其成为代码块
相关问题 更多 >
编程相关推荐