![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
All right! Hopefully we've all successfully completed Problem Set 0 and are ready to tackle Lecture 2. Note that there is a handout associated with this lecture, and having it printed out before starting is a really helpful thing. Not that I had to stop and print it in the middle of lecture or anything...
Also, since our problem set numbers started with 0, I'm going to put up a post for PS1 this Friday. From that point on, problem sets will go up every other week.
I had one problem with this lecture, and I'm hoping you all can facilitate a light bulb moment. The code example with x, y and z, the fourth one down the page... I can't figure out what the bug was. Is it just because the statements aren't indented, or is there something else?
Also, since our problem set numbers started with 0, I'm going to put up a post for PS1 this Friday. From that point on, problem sets will go up every other week.
I had one problem with this lecture, and I'm hoping you all can facilitate a light bulb moment. The code example with x, y and z, the fourth one down the page... I can't figure out what the bug was. Is it just because the statements aren't indented, or is there something else?
no subject
Date: 2010-01-10 10:05 pm (UTC)if x > y:
print x
But this is not correct:
if x > y
print x
no subject
Date: 2010-01-10 10:10 pm (UTC)But no, that's not it, there's a colon...
no subject
Date: 2010-01-17 02:37 pm (UTC)no subject
Date: 2010-01-17 09:59 pm (UTC)no subject
Date: 2010-01-10 11:23 pm (UTC)x = 15
y = 5
z = 11
print x,y,z
#Is this right?
if x < y:
if x < z: print 'x is least'
else: print 'z is least'
else: print 'y is least'
The problem with this code is that it doesn't consider different situations. This example compares x and y, and x and z, but it does not compare y and z.
So for example, if we say x = 15, y = 13, z = 11.
The code will look and say, okay, x is not less than y. It'll skip down to the else statement, and print 'y is least'.
In actuality, z is least, but the program never compares y and z.
(Reposted to fix a small mistake.)
no subject
Date: 2010-01-10 11:50 pm (UTC)Right?
no subject
Date: 2010-01-11 12:10 am (UTC)Consider a case where our intent is different: let's say we decide that if x is not less than y, then we don't care what z is. In that case, this code would be perfectly fine.
no subject
Date: 2010-01-11 12:26 am (UTC)no subject
Date: 2010-01-13 03:48 am (UTC)no subject
Date: 2010-01-13 04:01 am (UTC)no subject
Date: 2010-01-13 09:56 pm (UTC)no subject
Date: 2010-01-14 02:47 am (UTC)Thanks!
no subject
Date: 2010-01-14 11:19 pm (UTC)Okay. I'll annotate them and try to get them posted sometime tomorrow (Friday).
ionabdRgPETKlanJ
Date: 2012-01-06 05:02 pm (UTC)no subject
Date: 2010-01-14 11:21 pm (UTC)Oops—forgot to ask: Do I put them under this thread or start another?
no subject
Date: 2010-01-14 11:31 pm (UTC)McPLHfDdvRaKImSAU
Date: 2012-01-06 05:22 pm (UTC)gZFJGTwPZPOEkpw
Date: 2012-01-07 06:16 am (UTC)no subject
Date: 2010-01-14 02:49 am (UTC)