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

How do you write/ask user to input 10 integers and print out largest odd number? Stuck with Loops. Thanks

OpenStudy (anonymous):

Ok, in what language do you work?

OpenStudy (anonymous):

Python 2. 79 thank you

OpenStudy (anonymous):

ok, so first we need to input 10 integers, right? can you make a loop for that?

OpenStudy (anonymous):

unsure, but seems like loops is something should.

OpenStudy (anonymous):

ok, let's start with a single input and then add a loop for 10 inputs How would you get get a single integer?

OpenStudy (anonymous):

int(raw_input('enter int....'))

OpenStudy (anonymous):

ok, do you know to make a loop that runs 10 times?

OpenStudy (anonymous):

tried for x=int(raw-input..... while (x < 11):.....

OpenStudy (anonymous):

no it wouldn't work. your loop is depended on the input, and it shouldn't be. How about: ```python for i in range(10): pass ``` This will loop 10 times wouldn't it?

OpenStudy (anonymous):

It will do nothing really, but will loop 10 times.

OpenStudy (anonymous):

it seems to only give me 1 int. haven't learn 'pass' yet.

OpenStudy (anonymous):

Now, if we ask for input inside the loop: ```python for i in range(10): x = int(raw_input('enter int....')) ``` This will ask the user to enter 10 integers in a row, each time the value will get into x. So we have our first step, asking for 10 numbers

OpenStudy (anonymous):

Now we have to save the numbers we got from the user. Are you familiar with lists?

OpenStudy (anonymous):

been trying to understand for/while. once done, go to list

OpenStudy (anonymous):

it will be very annoying to make it without lists. in fact, without lists we are pretty much have to do it without loops, which will be very ugly. (imagine 10 input lines in a row into 10 different variables instead of what we have here.. you can see how bad it starts)

OpenStudy (anonymous):

thank you. i will read up on list and try again. i didn't want to ask input 10x. it would have been very annoying. Have to go. thank you so much

OpenStudy (anonymous):

Ok, cya =)

OpenStudy (rsmith6559):

You may want to consider downloading: http://www.greenteapress.com/thinkpython/thinkpython.html

OpenStudy (e.mccormick):

Another thing to think about is if you need anything other than the largest odd integer. If not, then why save anything other than the largest odd one you see?

OpenStudy (anonymous):

@e.mccormick No reason really =) I thought it would make it simpler to break it to smaller steps. First getting the numbers, then finding the maximum odd. Then after it all works and covers everything to optimize it and combine the loops and do some refactoring if needed

OpenStudy (e.mccormick):

With just one loop, you take it in, evaluate, and replace if needed. Then, after that loop, you print the result. Simpler. Cleaner. Only need 1 global and 1 local variable with 2 if statments. And no need to have learned arrays yet.

OpenStudy (anonymous):

Yes from the point of not needing knowledge about arrays I agree I know what you mean, I also see the final solution But from what I've seen this approach does help to simplify problems even if it seems dumb at first.. I've seen it taken in more complicated problems and I just liked the way it turned out at the end, that's all. It is arguable of course, but that's the way methodologies always are hehe

OpenStudy (anonymous):

Thank you e.mccormick and thanks again pitamar. I'll start reading and working.

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!