Python bootcamp · Lab 27

Countdown

easyFor Loops8 minLesson: For Loops

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read n and print the numbers from n down to 1, space-separated on one line.

range can count backwards: range(n, 0, -1).

Input. One line: an integer n ≥ 1.

Output. n space-separated integers, descending.

Constraints

  • 1 ≤ n ≤ 50

Examples

Example 1
Input
5
Output
5 4 3 2 1
Hint
  1. range(n, 0, -1) yields n, n-1, …, 1.
  2. print(*range(n, 0, -1)) does the whole job.
Show correct code

Peek only after you have tried. You can still Check your own version.

n = int(input())
print(*range(n, 0, -1))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.