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

Can someone explain to me why this produces only 5,4 and not 5,4,3? num = 5 if num > 2: print num num -= 1 print num I would have thought once the loop got to 3, it's still greater than 2, so it would print the 3?

OpenStudy (anonymous):

There is no loop. Maybe you meant to write "while" instead of "if"

OpenStudy (anonymous):

Thanks, not feeling particularly well and jumping ahead of myself. I knew it was something simple. Thanks :)

OpenStudy (anonymous):

It happens to all of us! Always good to have someone else read your code

OpenStudy (anonymous):

Thanks for such a quick reply. I was hoping someone would be able to look at it right away. That's what I like about Open Study. Do you find it's "always" that quick?

OpenStudy (anonymous):

Certainly not all programming problems are that quick, but many are caused by small oversights. Perhaps it's because I'm not an expert programmer, but I find most of my errors arise from foolish things leading to operations on null variables.

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!