write a program to display the first 10 natural numbers in descending order in python
Answers
Answered by
3
Explanation:
# Python Program to Print Natural Numbers in Reverse Order
number = int(input("Please Enter any Number: "))
i = number
print("List of Natural Numbers from {0} to 1 in Reverse Order : ".format(number))
while ( i >= 1):
print (i, end = ' ')
i = i - 1
Answered by
5
Required Answer:-
Question:
- Write a program to display the first 10 natural numbers in descending order in python.
Solution:
Here comes the program. This question is solved using loop.
for i in range(10,0,-1):
print(i,end=" ")
Explanation: The above loop goes in the range 10 to 1 (excludes 0) and after each iteration, value of 'i' variable is displayed. After displaying, the value of 'i' is decremented by 1.
One line códe for this question:
1. Using list.
print(* [i for i in range(10,0,-1)])
2. Using jóin() function.
print(" ".jóin(str(i) for i in range(10,0,-1)))
See the attachment for output ☑.
Attachments:
Similar questions