Some exercises which we may discuss in lecture first: 1. What does this code do: -------------------------------------------------- if False and False or True: print False else: print True 2. What does this code do: -------------------------------------------------- if False and (False or True): print False else: print True 3. How can you simplify: ---------------------------------------------------- (x < 5) and (x < 25) Assume x holds a number. 4. Likewise, how would you simplify each one of these: ---------------------- a) (x < 5) or (x < 25) b) (x > 3) or (x < 5) c) (x > 3) and (x < 5) 5. Consider the following two program fragments. Assume that x is an int variable. // fragment 1 | // fragment 2 | if x == 5: | if x == 5: x = x + 1 | x = x + 1 else: | if x != 5: x = 8 | x = 8 Which of these statements is true? a) The two fragments are logically equivalent. b) If x is 6 initially, then -- the value in x is 8 after executing fragment 1 and -- the value in x is 6 after executing fragment 2. c) Fragment 2 contains a syntax error. d) x always has the value 8 after executing fragment 2. e) x has either the value 5 or the value 8 after executing fragment 1. 6. Also, please simplify the following two statements: a) !(((x > 0) or (x == 0)) and (x < 10)) Warning: Don't overlook the logical negation (bang!) at the front. b) !(((x > 0) or (x == 0)) or (x < 10)) Warning: same as before. In both cases assume x is an integer. Does anything change if x is a float? Also I am going to post the code we develop in class below: for something in range(10): print "*", This code prints 10 stars, on the same line. for whatever in range(10): for something in range(10): print "*", print This code prints a 10 by 10 square of stars. size = int(raw_input("Please enter the size: ")) for line in range(size): for column in range(size): if line + column == size - 1 or line == 0 or line == size-1 or line == size/2 and size/3 <= column <= 2 * size / 3: print "*", else: print " ", print This code prints the scalable Z we talked about. In class we also developed a scalable 4: size = int(raw_input("Please enter the size: ")) for line in range(size): for column in range(size): if line + column == size / 2 or \ line == size / 2 and column <= 3 * size / 4 or \ column == size / 2 and line >= size / 4: print "*", else: print " ", print I'm going to add this to the study guide tonight.