打印以下的 Python 系列:

huangapple go评论71阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年7月13日 11:44:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76675753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定