Read the question, write Python on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
The first line is n. The second line has n integers. Print them in reverse order, space-separated.
Slicing with a step of -1 reverses any sequence.
Input. Line 1: n. Line 2: n integers.
Output. The values in reverse order, space-separated.
Constraints
- 1 ≤ n ≤ 100
Examples
Input
5 1 2 3 4 5
Output
5 4 3 2 1
Hint
- nums[::-1] reverses the list.
- print(*reversed(nums)) is the same idea.
Show correct code
Peek only after you have tried. You can still Check your own version.
n = int(input())
nums = list(map(int, input().split()))
print(*nums[::-1])
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.