问题描述
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 |
+------------------------------------------------------------------------------------------+