Q. Write a short program to print first n odd number in descending.


You can understand by Watching video :-



Answer :-

n = int(input("Enter value of n = "))
for i in range( (n * 2 - 1), 0 , -2) :
  print(i, end = " , ")  

Output :-

Enter value of n = 50
99 , 97 , 95 , 93 , 91 , 89 , 87 , 85 , 83 , 81 , 79 , 77 , 75 , 73 , 71 , 69 , 67 , 65 , 63 , 61 , 59 , 57 , 55 , 53 , 51 , 49 , 47 , 45 , 43 , 41 , 39 , 37 , 35 , 33 , 31 , 29 , 27 , 25 , 23 , 21 , 19 , 17 , 15 , 13 , 11 , 9 , 7 , 5 , 3 , 1 ,

>>> 

Enter value of n = 75
149 , 147 , 145 , 143 , 141 , 139 , 137 , 135 , 133 , 131 , 129 , 127 , 125 , 123 , 121 , 119 , 117 , 115 , 113 , 111 , 109 , 107 , 105 , 103 , 101 , 99 , 97 , 95 , 93 , 91 , 89 , 87 , 85 , 83 , 81 , 79 , 77 , 75 , 73 , 71 , 69 , 67 , 65 , 63 , 61 , 59 , 57 , 55 , 53 , 51 , 49 , 47 , 45 , 43 , 41 , 39 , 37 , 35 , 33 , 31 , 29 , 27 , 25 , 23 , 21 , 19 , 17 , 15 , 13 , 11 , 9 , 7 , 5 , 3 , 1 ,

>>> 


5 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Can't we just write the code without (n*2-1) and simply write it as (n,0,-2)

    ReplyDelete
    Replies
    1. No, If you write (n,0,-2) then it print odd number less than n only.

      Delete
  2. have a good day

    ReplyDelete
  3. n=int(input("Enter a number:"))
    if n%2==0:
    n=n-1
    for i in range(n,0,-2):
    print(i, end=',')

    Can we write this way?

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post