This lab has the following parts:
Turn in this page for your group
To which of the following is this expression equivalent:
not ((x > y) and (y <= 3))
(x > y) and (y <= 3)
(x > y) or (y <= 3)
(x < y) or (y >= 3)
(x <= y) or (y > 3)
(x <= y) and (y > 3)
This means 1800, 1900, and 2100 are not leap years but 2000 and 2004 are leap years.
Which of the following implementations of a method is_leap
returns true if year is a leap year and false otherwise. Circle those that are correct. If a method is not correct, provide a value for year for which it returns the wrong value.
def is_leap1 (year): if year % 400 == 0: return True if year % 100 == 0: return False if year % 4 == 0: return True return False def is_leap2 (year): return year % 400 == 0 or (year % 4 == 0 and year % 100 != 0) def is_leap3 (year): if year % 100 == 0: return False if year % 400 == 0 or year % 4 == 0: return True return False
all_same
that returns true only if all three of the given values are the same. For example, a call to all_same
with the values 3, 128, 255 should return False
; while the values 128, 128, 128 should return True
. def all_same (value1, value2, value3):
Write three separate programs that each print out the lyrics to the following common children's songs below. Your output of the song lyrics should be as similar as possible to what appears on the websites, including line breaks and blank lines. Although you do not need to write out the numbers (i.e., ninety-nine), it is okay to write 99 instead.
To print a single verse of each song, use as many functions as necessary to minimize simple repetition in your print
statements. Once you can correctly print any single verse of the song (using parameters to change what specifically is printed), write a loop to print the entire song by repeatedly calling your single verse function with different values generated within the loop.
String
) and the initial number of bottles of it on the wall (an int
) should be passed as parameters to a single function that prints the whole song.
Note that the program should use corect grammar so that it does not print plural "bottles" when there is only one bottle left (as shown below).
1 bottle of sarsaparilla on the wall
objects = [ "the whole world", "the itty bitty baby", "a-you and me brother", "a-you and me sister", "the whole world" ]
range
or a list), but it is easily done with an indefinite loop or even with no loop at all!