Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 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!
Latest Questions
TiredGhostboy: help
4 hours ago 3 Replies 0 Medals
TiredGhostboy: dose anyone understand
2 hours ago 1 Reply 1 Medal
MELLYWRLD: is it wrong if i believe in a lil of everything
11 hours ago 10 Replies 1 Medal
MELLYWRLD: I Kinda New...anyone wanna explain what this sites about
11 hours ago 13 Replies 1 Medal
TiredGhostboy: help
12 hours ago 3 Replies 3 Medals
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!