Ask
your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW)
37 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
Breathless:
give me a subject or idea for a valentine love story!
JBlizzy:
I don't really understand myself here recently I've been messing up everything I
zanesafoodie:
ITS THAT TIME AGAIN FOLKS! (Btw I am NOT promoting Disney) (TW: cussing) This one's called "disney you lied to me" my dreams weren't meant to be despite Dis
danielfootball123:
I really want to get into coding, can anyone help (web dev/game dev)
Lillys2account:
u201cOverthinkeru2019s Anthem" My mindu2019s a movie on replay, Every little word I said today.
jhaseker:
In relationship I thought I would find true love After all it had such A wonderfu
penguin:
people say its okay for them to do stuff but not when i do stuff so u mean it is
zanesafoodie:
This one's called thanks I guess (also I am SO sorry for not posting anything in
YouMyPlug:
Petition to make a subject for videogame clips or games in general. Trust
34 minutes ago
14 Replies
2 Medals
1 hour ago
1 Reply
0 Medals
1 hour ago
12 Replies
0 Medals
5 hours ago
31 Replies
2 Medals
1 hour ago
7 Replies
1 Medal
1 hour ago
6 Replies
0 Medals
1 hour ago
4 Replies
1 Medal
1 hour ago
9 Replies
2 Medals
4 days ago
4 Replies
0 Medals