Hello guys, I am doing problem set 1 of the 2008 course. I am completely lost as to how to generate all odd numbers and then test them. Anyone that can help with some guidance? Thank you. Also, which of the courses do you find more appropriate for a beginner? Thanks.
This is the closest I am: x = 24 y = range(3, x, 2)
You can google the documentation for many functions in python. Here is a bit about range: https://docs.python.org/release/1.5.1p1/tut/range.html what you wrote; ``` x = 24 y = range(3, x, 2) ``` will save an array to y. When saving the array, you told it to start at 3, end at x (note the 3 is inclusive, and x is exclusive) -- and you told it to add 2 between each element. In other words, it will save this array: ``` [3, 5, 7, 9... 23] //to y ``` You can check what values were saved to the list by doing this code: ``` x = 24 y = range(3, x, 2) yArrayLength = len(y) accumulator = 0 while(accumulator < yArrayLength): print(y[accumulator]) accumulator = accumulator + 1 print(' ') ``` note that len(y) will give how many 'elements' are in the list y to variable yArrayLength. You identify each element in a list by telling the array what index you want-- for example: ``` listX = [3, 4, 5, 6, 7, 7] print[0] print[2] ``` That will print: ``` 3 5 ``` this is because 0 indicates the first element in the array (aka; list), and 2 indicates the 3rd element in the array. Using the array length, I make a loop that will cycle as many times as there are elements in the array to be read.. I also keep a variable called accumulator, which keeps track of which cycle number (cycles are also called iterations) the loop is on- so I can use the value stored in accumulator to tell the program which element in the array to print. As far as the best python class to take -- I'm not sure, I haven't taken them myself, nor am I much good at python. Though quite a few people at this site have been down that road, I'm sure some people will share their 2 cents on it.
Thanks man, I will try using these tools.
Join our real-time social learning platform and learn together with your friends!