Computer Science, asked by aadityagoyal51, 2 months ago

in python
Write a program to print the square of first twenty natural numbers in descending order​

Answers

Answered by jai696
3

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

print("\n".join([str(n ** 2) for n in range(20, 0, -1)]))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by anindyaadhikari13
2

Required Answer:-

Question:

  • Write a python program to print the squares of first twenty natural numbers in descending order.

Solution:

This is an easy question. Here is the code.

for i in range(21,0,-1):

print(i**2,end=" ")

This can be solved in 1 line too!! Here is the code.

>> print(" ".join(str(i**2) for i in range(21,0,-1)))

For verification, check out the attachment.

Logic:

  • A loop is created that iterates 20 times. After each iteration, you can see that the value of i becomes 20, 19, 18,....1. After each iteration, square of i is displayed on the screen. Only one variable is used (i).
Attachments:
Similar questions