INSS 250

Jocra6
hw02-functions.pdf

Homework 2: Functions Due: Saturday, 3/9/2019

General Instructions:

1. Save your file as lastname_hw.py

2. Submit your assignment on Blackboard, no emails.

3. Do not wait until the last minute to get started. Computers crash, wireless goes down, etc. Be

prepared, no excuses!

4. Individual submissions, do not submit code that is not your own!

Specific Instructions:

You will write five python functions for practice with the language. Include each of the following

functions in your file. Do not include calls to the functions; remove them (or comment them out)

before submission. Be sure to capitalize the function names as they are listed below.

1. superman

2. largest

3. compliments

4. leapYear

5. comboLock

Function descriptions:

Function #1: superman Parameters: height - an integer representing the user's height in inches

Description:

Write a function for the Superman ride at Six Flags that determines whether the user is taller than

4'8" so that he or she can ride a roller coaster. If the user's height, which is provided by the

parameter height, is greater than or equal to the minimum height, print the string 'Have a great

ride!'. Otherwise, print the string 'Sorry. You must be at least 4 feet 8 inches to ride.' Test Cases:

>>>superman(30) Sorry. You must be at least 4 feet 8

inches to ride.

>>>superman(70)

Have a great ride!

Function #2: largest

Parameters:

num1 - a floating point number being compared against num2 and num3

num2 - a floating point number being compared against num1 and num3

num3 - a floating point number being compared against num1 and num2

Description:

Write a function that takes in three numbers as parameters and prints out the largest of the three. If two

or all of the numbers are equal, or even all three, then just print the value once.

Test Cases:

>>>largest(433.1, 2340.32, 12323.7)

12323.7

>>>largest(12.0, 32.1, 32.1)

32.1

>>>largest(23.44, 23.44, 23.44)

23.44

Function Name: compliments

Parameters:

answer1 - a boolean (True or False) representing whether the user is "smart"

answer2 - a boolean (True or False) representing whether the user is "awesome"

answer3 - a boolean (True or False) representing whether the user is "fun"

Description:

Write a function that outputs a string of compliments based on the adjectives selected by the inputs.

Use the inputs True and False. The function should return the string “You are” concatenated with the

compliments that are true. The three compliments should be: "smart" "awesome" and "fun". If none of

the compliments are true, print the string “Goodbye.” instead.

Test Cases:

>>>compliments(True, True, True) You

are smart awesome fun.

>>>compliments(False, True, False)

You are awesome.

>>>compliments(False, False, False)

Goodbye.

Function Name: leapYear Parameters: year – an non-

negative integer representing the year Test Cases:

>>>leapYear(1996) The year 1996 is a leap year.

Enjoy your extra day!

>>>leapYear(1901) The year 1901

is not a leap year.

Description:

Write a function which calculates whether or not a given year is a leap year and has 366 days instead

of 365. A general algorithm is as follows:

1. A year will be a leap year if it is divisible by 4 but not by 100.

2. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.

Years such as 1996, 1992, 1988 and so on are leap years because they are divisible by 4 but not by

100. For century years, the 400 rule is important. Century years (ex: 1900, 1800, 1700) are exactly

divisible by 4 AND exactly divisible by 100. They are not divisible by 400 and are thus not leap years.

You fuction should print out "The year XXXX is a leap year. Enjoy your extra day!" if the year

XXXX is a leap year. Print "The year XXXX is not a leap year." if the year XXXX isn't a leap year.

Function Name: comboLock

Parameters:

num1 – a positive integer representing the first digit in the combination

num2 – a positive integer representing the second digit in the combination

num3 – a positive integer representing the third digit in the combination

num4 – a positive integer representing the fourth digit in the combination

num5 – a positive integer representing the fifth digit in the combination

Description:

You own a combination lock that only opens when presented with the correct sequence of odd and

even numbers that are less than 10. Write a function that takes in 5 integers. Check whether they are

in this order: odd, even, odd, even, odd. If they are in the correct order and all below 10, then print

the string “You opened the lock.” Otherwise, print “You are locked out.” Test Cases:

>>>comboLock(9, 2, 5, 4, 1) You

opened the lock.

>>>comboLock(1, 8, 3, 6, 8)

“You are locked out.”

comboLock(2, 2, 5, 6, 4)

“You are locked out.”

>>>comboLock(9, 8, 7, 8, 10)

"You are locked out."

Grading:

Total 200 points

All code should work as described for each function, no errors. Please pay attention to

logic and calculations. Submit via Blackboard. No email submissions accepted. You can

write all functions in the same python file or submit zipped folder containing files with

each function.40 points each, function works as described (max. 30 pts), logic and

calculations(max. 10 pts).