jetamors: Yoruichi is really hot (Default)
Jetamors ([personal profile] jetamors) wrote in [community profile] intro_to_cs 2010-01-10 11:23 pm (UTC)

C&Ping the code to make it clearer:

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.)

Post a comment in response:

This community only allows commenting by members. You may comment here if you're a member of intro_to_cs.
(will be screened if not on Access List)
(will be screened if not on Access List)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting