+ 2
Write a Short Program to Print First n Odd Numbers in Descending Order in Python??
Please in Simple Way AS I am New...I Know about if,else elif ,for loop, while loop etc
4 Respuestas
+ 4
You need to print series 2n-1, 2(n-1)-1, 2(n-2)-1, ...,5, 3, 1
You can do (n<<1)-1 as done by Jay Matthews sir as it means (2*n)-1 only & then substract 2 in each iteration till 1 is reached, OR
just run a loop from n=n to n=1 & print (2n-1) in each iteration.
KfirWe your solution will print ascending series not descending.
+ 3
KfirWe
My answer was for unedited code in your comment, now the solution is correct👍
+ 1
n = int(input("Enter the numbers : "))
OddNumbers = []
for i in range(n*2):
if i % 2 != 0:
OddNumbers.append(i)
OddNumbers.reverse()
for i in OddNumbers:
print(i)
Hope i get the question right :)
- 1
Gaurav Agrawal
IDTS