英文:
Printing the following series in python
问题
在Python中打印以下模式:
20, 19, 18...1
for x in range(20, 0, -1):
print(x)
但是当我执行它时,输出窗口总是空白的。我也检查了缩进,但仍然是一个空白窗口。非常感谢帮助。
英文:
Print the following pattern in Python:
20,19,18...1
for x in range (21,2):
x=x-1
print(x)
but when I execute it, the output window comes blank whenever I execute it. I checked the indents too, but still a blank window.
Help is extremely appreciated.
答案1
得分: 1
使用范围如下:
range(21, 2, -1)
不包括 x=x-1
英文:
Use range like this:
range(21,2,-1)
Don't include x=x-1
答案2
得分: 1
需要明确指定范围向后移动的方式,使用第三个值:
for x in range(21, 1, -1):
x = x - 1
print(x)
并且您可以更改范围值,无需使用 x-=1
:
for x in range(20, 0, -1):
print(x)
英文:
You need to explicit specify that range goes backwards with third value:
for x in range(21,1,-1):
x=x-1
print(x)
and you can change range values that there is no need for x-=1
:
for x in range(20,0,-1):
print(x)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论