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

I'm having trouble with problem 2 in problem set 1.so far i did this & getting an error:: from math import * count = 0 i = 1 limitnum = raw_input('Enter the limit of the range') for i in range(2,limitnum): if limitnum/i == 0: break; else: count= count+ log(i+1) i = i + 1 print log(i)

OpenStudy (maitre_kaio):

You probably want to use % (modulo), not / (integer division) For example: 13 / 5 = 2 and 13 % 5 = 3

OpenStudy (anonymous):

Were you able to solve Problem 1 successfully? If so, please post the code. Problem 2 builds on Problem 1 and requires only a slight modification.

OpenStudy (anonymous):

problem 1: prime = 0 number = 1 while prime < 1000: number = number + 1 # starting from 2 # testing if the number is prime or not divisor = 2 numberIsPrime = True while divisor*divisor <= number: if number % divisor == 0: numberIsPrime = False break divisor = divisor + 1 # found one? if numberIsPrime: prime = prime + 1 print number

OpenStudy (anonymous):

problem 2 is giving an error:File "C:\Python25\ps1b.py", line 11, in <module> for i in range(2,limitnum): TypeError: range() integer end argument expected, got str. still can't slove.

OpenStudy (anonymous):

@maitre_kaio:thanx for highlighting the logical error,but i think it's giving me a syntax error.isn't it??i have post it above.

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!