Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
15 Online
I don't get the program at the end of lecture 3. http://dpaste.com/603441/ why is the result 17?
Still Need Help?
Join the QuestionCove community and study together with friends!
The function is summing the digits of the string, so 1+9+5+2 = 17
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!
Join our real-time social learning platform and learn together with your friends!
Latest Questions
Countless7Echos:
I don't know just no sketch doodle day :p finished a video already so I'm pretty
Ferrari:
Depression Hi, it's me, Jordan (ferrari). It's supposed to be the Fourth of July but I feel kinda depressed and mad at myself for no reason.
Countless7Echos:
mmm I forgot to post but hey first time trying out hyperpop art :3 super fun TW:
RAVEN69:
The hole You can't fix the hole in my heart. It's permanent. It's been broken to many times and I love it every time.
10 hours ago
8 Replies
2 Medals
29 minutes ago
12 Replies
1 Medal
1 day ago
9 Replies
5 Medals
1 day ago
0 Replies
0 Medals