Lecture 3

Nov. 16th, 2009 05:44 pm
elz: (ada-tubes)
[personal profile] elz posting in [community profile] intro_to_cs
Link to video and handout + Problem set 2






Open to: Registered Users, detailed results viewable to: All, participants: 9


How's it going?

View Answers

Finished lecture 3
9 (100.0%)

Finished problem set 2
3 (33.3%)

Date: 2009-11-17 02:22 am (UTC)
zulu: (muppets - huh)
From: [personal profile] zulu
Ah, cool, well at least I understand what the error message is telling me now, thanks.

What I was trying to do was to sum up the logs of each item in my tuple (which I also tried with a list and that didn't work either). I thought the point of tuples was that I could do my function on each item and then move on, rather than doing each one individually, like:

log(2) + log(3) + log(5)

et cetera.

I do see the problem now with assigning the name of "sum"--I shouldn't do that because it's one of the restricted words. *nods*

Well, I still don't know how to do this, but now I know one way of not doing it, which is a pretty good start. Shall try again tomorrow when I have teh brainz.

Date: 2009-11-17 04:17 am (UTC)
yhlee: Alto clef and whole note (middle C). (Default)
From: [personal profile] yhlee
For summing up the logs you'd need a new function that takes in a tuple. Basically:

def logSum(tuple):


and make sure there's a tab indent for the next line, where you define the block of code. What you'll probably want to do is get the length of the tuple, then use that to define a while loop (or you could do this with a for loop but I'd have to look up the syntax), looping over each item in the tuple: take the log, then add it to a running sum variable. At the end you'll want to return the running sum. Does that help a little?

Profile

Introduction to Computer Science

July 2010

S M T W T F S
    123
45678910
11121314151617
18192021222324
2526272829 3031

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 14th, 2025 04:53 pm
Powered by Dreamwidth Studios