I have this question that I've been trying to solve for the past hour but i've been getting it wrong, can someone help me?

Question:
Create a list of the odd numbers between 1 and n (include 1 as well as n -- if it's odd-- in the list). Associate the list with the variable odds .

My code:
odds = [1]
i = 0
for i <= n:
if i%2 != 0:
odds.append(i)
i+= 1

try this
gives you the idea. no checkups anyway

#Find odd numbers

def odd_find(fr, to):
    if fr > to:
        trans = fr
        fr = to
        to = trans
    odd = []
    noOdd = []
    
    for x in range(fr, to):
        if x % 2 == 0:
            odd.append(x)
        else:
            noOdd.append(x)

    print  'Odd Stuff', odd
    print 'Not odd', noOdd

odd_find(5,40 )

print out:
Odd Stuff [6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]
Not odd [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]

;)

We do not know context of your studies to know the purpose of this exersise. The purpose surely is not the correct output which can be directly produced with basic functions.

Odd Stuff [6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38]
Not odd [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]

6 is even, 5 is odd, Your definition of even is odd :) And you are confusing the poor guy!

haha,

tonyjv

Cant you see that it was just a mistake with naming?
Take it easy ok?

print 'Input n'
n = int(raw_input())
data = []
i = 1
while i <= n:
	data.append(i)
	i+=2

print data

We are not supposed to help to write the code but get this OP to learn from writing the code, anywhere here the code (without error handling):

print range(1,int(raw_input('Give the end: '))+1,2)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.