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

Hello everyone! I want a little help on this code. What's the error? .... def isWordGuessed(secretWord, lettersGuessed): j=0 if len(lettersGuessed)==0: return False for i in range(len(secretWord)): for k in range(len(lettersGuessed)): if secretWord[i]==lettersGuessed[k]: j+=1 else: j=j if j>=len(secretWord): return True else: return False

OpenStudy (anonymous):

Ac.. to what i got from your code, you must move the last if-else block out of for-loops as the condition in if-else block i.e. j>=len(...) is never going to be true and it'll return false in first step of for loop. Plus the j=j statement is also not needed in else block. def isWordGuessed(secretWord, lettersGuessed): j=0 if len(lettersGuessed)==0: return False for i in range(len(secretWord)): for k in range(len(lettersGuessed)): if secretWord[i]==lettersGuessed[k]: j+=1 if j>=len(secretWord): return True else: return False print(isWordGuessed("Hello", "Hello"))

OpenStudy (anonymous):

Ya. Exactly. Thank you. Actually, I'm a C++ programmer, so i don't know perfect syntex of python.

OpenStudy (anonymous):

And have you completed computeRoot function(Newton-Raphson method) in previous problem?

OpenStudy (anonymous):

I'm also, but i'm not studying courses here (from MIT/OCW), im studting from Udacity.

OpenStudy (anonymous):

Great! Can you help in one more problem which one I'm going to post?

OpenStudy (anonymous):

This is the code, in which we have to compute a root using Newton-Rashson method.... def computeRoot(poly, x_0, epsilon): i=0 if len(poly)==1: root=0 elif len(poly)>1: root=x_0 while evaluatePoly(poly,root)<abs(epsilon): deriv_poly=computeDeriv(poly) root=root-(evaluatePoly(poly,root)/evaluatePoly(deriv_poly,root)) i+=1 a=[root,i] return a

OpenStudy (anonymous):

hey! Are you there?

OpenStudy (anonymous):

Wait

OpenStudy (anonymous):

Wait is problem ?

OpenStudy (anonymous):

ok

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!