如何解决我是一个初学者请解决这个问题以下代码会导致无限循环您能找出缺失的地方以及如何解决?
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 |
+------------------------------------------------------------------------------------------+
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。