# Week 7 practice problems, by chaynes@indiana.edu def not_fun(a): """ Return False if a is a true value, and True otherwise. Do not use boolean operator. >>> not_fun('Spam') False >>> not_fun(False) True >>> """ #. #. #. #. def or_fun(a, b): """ Return True if a or b are both true values, and False otherwise. Do not use a boolean operator. >>> or_fun(True, False) True >>> or_fun(0, '') False >>> """ #. #. #. #. #. #. def blastoff(n): """ Print the integers from n down to 1, in descending order, one per line, and then print "Blastoff". >>> blastoff(2) 2 1 Blastoff >>> """ #. #. #. #. def leap_year(year): """ Return a boolean indicating if int year is a leap year. A year is a leap year if it is evenly divisible by 4 (that is, there is no remainder when divided by 4), and it is not evenly divisible by 100, with the exception that years evenly evenly divisible by 400 are leap years. >>> leap_year(2006) False >>> leap_year(2004) True >>> leap_year(1900) False >>> leap_year(2000) True >>> """ #... def right_justify(n, string): """ Returns the string with enough blanks added at the beginning to make it n characters long. >>> right_justify(5, 'foo') ' foo' >>> """ return ' ' * (n - len(string)) + string def lower_triangular_mult_table(n, width): """ Print an n by n multiplication table in which each column has the indicated width. The table is printed as a "lower-triangle" removing the redundancy in a full table (since a*b = b*a) by not printing values above the diagonal. >>> lower_triangular_mult_table(9, 4) 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 >>> """ i = 1 while i <= n: j = 1 line = '' #... line = line + right_justify(width, str(i * j)) j = j + 1 print line i = i + 1