0

Write a program to print first N odd numbers in descending order(python)

from python

10th Sep 2018, 6:14 AM
tonu ji
3 Antworten
+ 1
n=10 # N odds = [x for x in range(1,n*2,2)] print(odds) === output === [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
10th Sep 2018, 7:42 AM
strawdog
strawdog - avatar
+ 1
^ [::-1]
10th Sep 2018, 9:29 AM
Markus Kaleton
Markus Kaleton - avatar
0
Markus Kaleton Thanx, I've forgotten about the last condition. So the code will be : >>> n=10 >>> odds = [x for x in range(1,n*2,2)] >>> print(odds[::-1]) [19, 17, 15, 13, 11, 9, 7, 5, 3, 1] >>>
10th Sep 2018, 12:19 PM
strawdog
strawdog - avatar