+ 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

8th Sep 2019, 9:18 AM
Dope Tube
Dope Tube - avatar
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.
8th Sep 2019, 10:04 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
KfirWe My answer was for unedited code in your comment, now the solution is correct👍
8th Sep 2019, 10:24 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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 :)
8th Sep 2019, 9:37 AM
KfirWe
KfirWe - avatar
- 1
Gaurav Agrawal IDTS
8th Sep 2019, 10:10 AM
KfirWe
KfirWe - avatar