我是一个初学者请解决这个问题以下代码会导致无限循环您能找出缺失的地方以及如何解决?

问题描述

1  def print_range(start,end):
2     # Loop through the numbers from start to end
3   n = start
4   while n <= end:
5       print(n)
6  print_range(1,5)  # Should print 1 2 3 4 5 (each number on its own line) 

第6行应打印“ 1 2 3 4 5”(每个数字在其自己的行上),但不打印。为什么呢?

解决方法

n始终具有start的值,因为它从未在while循环中递增。 与for循环相比,while不会自动更改您迭代的变量。

因此,您需要在第5行和第6行之间:

n += 1
,
mysql> select concat(case when month(now()) >= 10 then year(now()) else year(now()) - 1 end,'-10-01');
+------------------------------------------------------------------------------------------+
| concat(case when month(now()) >= 10 then year(now()) else year(now()) - 1 end,'-10-01') |
+------------------------------------------------------------------------------------------+
| 2020-10-01                                                                               |
+------------------------------------------------------------------------------------------+

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...