Hi, just started python at Uni and think i am in for a rough ride with zero > prior experience in programming. > Anyway my problem that i can't fix my self after googling. > > The exercise is to generate a list of odd numbers between 1-100 and the > same > for even numbers. > > So far this is what i have > way to display numbers 1 - 100 > numbers = range(100)
> this gives me numbers= range(0,100) as an output in python 3.0 > I find it easy to do all this stuff with list comprehensions, but i am a beginner so this might not be the most efficient way to do it numbers=[] for x in range(1,101): numbers.append(x) > #A way to display all odd numbers > odd = numbers[::2] > instead i do this: odd=[] for y in range(1,101,2): odd.append(y) > #A way to display all even numbers > even=[] for z in range(2,101,2): even.append(z)
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor