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

from math import *#this code includes a check-up b=1 while(b!=0): b=int(raw_input("number")) x=3 n=2 y=log(2)+log(3) while (n3): a=a-2 else: y=y+log(x) a=1 n=n+1 print x y=y-log(x) print y print (y/x)#in the beginning of RUN press ENTER(if there is an empty space) This is ps1 p2.Can you find more efficient way to solve this problem?I think mine is too long and runs slow

OpenStudy (anonymous):

pls use a code pasting site - http://dpaste.com/667071/

OpenStudy (anonymous):

you should use comments and descriptive variable names seems to get the right answer but i can't figure out what it is doing

OpenStudy (anonymous):

bwCA-whats that for?

OpenStudy (anonymous):

it is set on an infinite loop so you can check sum of log to number n using different n's.You will notice as n increases ratio gets closer to 1

OpenStudy (anonymous):

I will answer what I can for bwCA. The code pasting is for the easiness of reading the code with syntax highlighting, and it doesn't mess up with the indentation, as pasting like you did does. The commentaries and descriptive names are a must. Python is a loosely-typed language, and when the programs start to get bigger, it is almost impossible to understand (even if you are the one who did the code). Even this piece of code, when you see it again in a couple of months, likely you won't remember what it does and how it works. Avoid using a, b, stuff like that for variable names. Rather, use sumofLogs, numtoTest, and the likes :-) Kudos for the solution, mate.

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!