Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 11 Online
OpenStudy (anonymous):

Can anyone help out with the 1.8 exercises? I'm a bit stuck on both 3 and 4.

OpenStudy (anonymous):

!.8 q3 I haven't coded it yet, but an exponential is just repeated multiplication so a**3 is a*a*a It looks like the number of times the multiplication takes place could be controlled by the loop.

OpenStudy (anonymous):

Thanks, I think I got the exp and base one, just working on the even number one now. I keep getting an infinite loop :)

OpenStudy (anonymous):

If the while loop tests for an odd number, control should fall out of it when an even number is entered.?

OpenStudy (anonymous):

Yeah, I get it to not be infinite now, but I believe it is supposed to keep asking you to enter an even number until you do, so that's all I have left, but I'll have to do that another day.

OpenStudy (anonymous):

The thing is you need to ask for the number in TWO places. Once before you enter the loop and then once inside the loop. At least that's what I did.

OpenStudy (anonymous):

The way I did it was I began by creating a test variable and setting it to False I then created a loop that ran while the test variable was False; in this loop, I prompted for the number, checked that it was even, and changed the test variable to True if it was. If the entry was something other than an even number, the test variable stayed False, the loop restarted, and the user was prompted again.

OpenStudy (anonymous):

Thanks all for the help - I got it :)

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!