I have no clue how to start this
Use the for and while iterative structures within Python to program a loop that generates a list of odd numbers from 1 to 33 inclusive. (two sets of code here!)

6 Years
Discussion Span
Last Post by richieking

You need to show some effort! We won't write out the code for you. Research for and while loops on the official python documentation. Make a variable that will be the condition for the loop. Increment this by two each time, making sure it starts on one, and stops when it reaches 33.


import random
for i in range (5):
# random integer: 1 <= number <= 33
print random.randint(1, 34)
I got this for the for statement but i cant get it to exclude evens, and loop

import random
while 1:
print random.randrange (0,34)
and I got this for the while but I cant get it to exclude evens


Why random number?

Can you say odd numbers from smallest to biggest until 33 inclusive? How could computer do the same?

Edited by pyTony: n/a


That would be a good idea Convoluted, but it may overcomplicate things. You just need a simple loop where you have a variable, say "i" (starting at 1), then each loop iteration, you write the value of "i" to an array each each loop, the position of which increases by 1.


Try and have a good around in the other threads. This has been done myriad times.

Edited by richieking: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.