Review Questions: Part 4

Question 1: Write a function that takes a number between 1 and 4 and returns the name of the season that represents according to the chart below.

 

Number

Season

1

Winter

2

Spring

3

Summer

4

Fall

 

 

Question 2: Write a function that takes 3 numbers as arguments and returns the biggest one. You can assume the three numbers will be different.

 

Question 3: Write a function that takes a single argument called temperature. This function should return “ nice” if the value of the argument temperature is between 69 and 77 (inclusive). If the temperature is less than 69, this function should return “cold”, and if the temperature is greater than 77, the function should return “hot”.

 

Question 4:  The following function takes a year and returns True if it’s a leap year and False otherwise. Don’t worry about understanding how it works.  Use this in part 4a and 4b

# this function returns True if year is a leap year and False otherwise

# Don't worry about understanding it!!

 

def is_leap(year):

    if year < 1753:

        return False

    else:

        mod4 = year % 4

        mod100 = year % 100

        mod400 = year % 400

 

        if mod400 == 0:

            return True

        elif mod100 == 0:

            return False

        elif mod4 == 0:

            return True

        else:

            return False

 

4a) Write a function that takes a single year  as an argument and prints out whether the year before, that year, and the next year are leap years

 

4b) Write a function that takes a single year as an argument and prints out the first year AFTER that year that is a leap year.