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

iwant know where is the mistake of this code sumDigits = 0 for c in str(1952): sumDigits += int(c) print(sumDigits) x = (100) divisors = () for i in range(1,x): if x%i == 0: divisors = divisors+(i,) print(divisors) print(divisors[0] + divisors[1]) print(divisors[2:4])

OpenStudy (e.mccormick):

Well, what is it supposed to be doing vs. what is it doing?

OpenStudy (e.mccormick):

Another thing that can help is to add in a divider so you can tell what each of the loops is doing: ``` sumDigits = 0 for c in str(1952): sumDigits += int(c) print(sumDigits) x = (100) divisors = () for i in range(1,x): if x%i == 0: divisors = divisors+(i,) print(divisors) print(divisors[0] + divisors[1]) print(divisors[2:4]) print("---") ``` See, that way the output is: ``` >>> 1 (1, 2, 4, 5, 10, 20, 25, 50) 3 (4, 5) --- 10 (1, 2, 4, 5, 10, 20, 25, 50) 3 (4, 5) --- ``` and so on. That is much clearer as to when you step through the `for c in str(1952):` loop.

OpenStudy (anonymous):

drowning plz help

OpenStudy (e.mccormick):

Well, I need to know what it is supposed to do. Right now it is just a block of code with no explanation.

OpenStudy (anonymous):

thank you e.mccormick iwas write this code and runed thank you for you

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!