Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

I'm doing Problem 1.1 here: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset1a.pdf I'm finding all odd numbers first. How can I turn this into a function called findodd? ''' c = 0 a = 1 x = int(raw_input("Enter your limit. ")) for a in range(1, x): while a % 2 > 0: print a, "is odd" a = a + 1 c = (c + 1) break else: print a, "is even" a = a + 1 c = c print "There are", c, "total odd numbers" '''

OpenStudy (anonymous):

This is not the final procedure to find odds for the Problem Set question, by the way. I am thinking my next step would be to take out the "prints" and if the number is odd, add it to a candidate list that I can use later on in the process of determining higher primes. Am I on the right track there at all, either?

OpenStudy (anonymous):

``` >>> >>> def foo(n): n = n + 2 n = n / 3. return n >>> foo(5) 2.3333333333333335 >>> ``` http://docs.python.org/2.7/tutorial/controlflow.html#defining-functions

OpenStudy (anonymous):

This function tell you if the number(x) is odd or even. def odd_or_even(x): if x%2 == 0: print x, "is even" else: print x, "is odd"

OpenStudy (anonymous):

Thanks for the help, both of you. I was just overthinking it, under-testing it, rushing, and putting everything in the wrong place. lol :P I think I've got it figured out now. I'm going to post the finished assignment in a separate question for feedback. Thanks again!

OpenStudy (anonymous):

You're welcome.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!