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

I don't get the program at the end of lecture 3. http://dpaste.com/603441/ why is the result 17?

OpenStudy (anonymous):

The function is summing the digits of the string, so 1+9+5+2 = 17

OpenStudy (anonymous):

sumDigits = 0 for c in str(1952): sumDigits += int(c) print sumDigits yeah, the for loop takes each digit, starting with the first and adds it to the previous, then prints the final result after the loop ends. sumDigits equals 1 on the first go around, then it equals 1 + 9 (10), then 10 + 5, etc.

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!