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

MOOC question, I'm working on the handout for week 2 section 1.8, and I'm stuck and not really sure how to begin solving the first part. Here is the exercise: "Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3, 1/4,..., 1/10. " First, I am not sure how you get the program to print out the fractions in float (decimal) form, and in consecutive order...is that the range function?

OpenStudy (anonymous):

Maybe take a look at the Tutorial in the Python docs. http://docs.python.org/2.7/tutorial/controlflow.html#for-statements Python versions 2.x do integer division. If you want a float as a result just make sure one of the operands is a float - 1.0 / 2

OpenStudy (anonymous):

at least one of operand needs to be float and you can use range in variable so you can then do pretty much straightforward code. Ask for showing code if you want.

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!