Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
11 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
Spongeboy:
A mutant cell line expresses a constitutively active \(G_{\alpha s}\) subunit coupled with a complete loss-of-function mutation in phosphodiesterase (PDE),
SaltySuga:
how deep must a cut be before its considered life threatening?
EdwinJsHispanic:
"parents" Crazy how parents can be master manipulators yet someone you love so freaking dearly, But its confusing.
JohnnyFowler2008:
How do you struggle with depression and not give up?
Kimmee1001:
Who or what is ultimately responsible for Romeo and Juliet's deaths?
EdwinJsHispanic:
is it normal to have high expectations, like expecting your partner to have time
gelphielvr:
Advice for cramming 70 vocab terms each week? Taking med term this year and we have to memorize about 70+ vocab terms per week and im having trouble studyin
EdwinJsHispanic:
I lowk need help deciding what I should write/type on this essay about why teache
GRIZZLEY19:
Let me know what y'all think about the story Image waking up and seeing a family in the dark.
38 minutes ago
0 Replies
0 Medals
41 minutes ago
1 Reply
0 Medals
22 hours ago
0 Replies
0 Medals
2 days ago
0 Replies
0 Medals
1 day ago
1 Reply
0 Medals
23 hours ago
5 Replies
1 Medal
2 days ago
4 Replies
0 Medals
1 day ago
3 Replies
0 Medals
2 days ago
22 Replies
6 Medals