Created
September 29, 2016 04:13
-
-
Save jjlumagbas/3a266edc8e3b20587670ec45925661a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns the larger value of either x or y, given x and y are numbers (Note: what value should be returned if they are equal?) | |
def max_of_2(x, y): | |
""" | |
Num, Num -> Num | |
Returns the larger of the two given numbers | |
""" | |
if (x > y): | |
return x | |
else: | |
return y | |
# print(max_of_2(1, 2)) # expect 2 | |
# print(max_of_2(2, 1)) # expect 2 | |
# print(max_of_2(2, 2)) # expect 2 | |
# Calculates my daily pay, given the number of hours. | |
# The regular hourly rate is 80/hr, | |
# the overtime rate is 120/hr. | |
# When I work overtime, the overtime rate applies | |
# to ALL the hours worked today. Otherwise, | |
# the regular rate applies. Any work over 8 hours | |
# is overtime | |
# -> Num | |
# return 0 | |
# -> Bool | |
# return False | |
# -> String | |
# return "" | |
RATE = 80 | |
OVERTIME = 120 | |
MIN_HOURS = 8 | |
def daily_pay(hours): | |
""" | |
Num -> Num | |
Calculates my daily pay, given the number of hours. | |
""" | |
if (hours <= MIN_HOURS): | |
return RATE * hours | |
else: | |
return OVERTIME * hours | |
# print(daily_pay(8)) # 80 * 8 = 640 | |
# print(daily_pay(10)) # 120 * 10 = 1200 | |
# 1. [Signature, purpose and stub](#1) Run! | |
# 2. [Define examples](#2) Run! | |
# 3. [Template and inventory (create constants)](#3) | |
# 4. [Code the function body](#4) Run! | |
# 5. [Test and debug until correct](#5) | |
# Create a function that produces that absolute value | |
# of a given number | |
def absVal(num): | |
""" | |
Num -> Num | |
Produces the absolute value of a given number | |
""" | |
if (num < 1): | |
return -num | |
else: | |
return num | |
print(absVal(-1)) # 2 | |
print(absVal(1)) # 2 | |
# categories of inputs | |
# edge case/boundary cases | |
# 100% code coverage | |
def is_teenager(age): | |
if (age < 19): | |
return True | |
else: | |
return False | |
is_teenager(8) | |
is_teenager(19) | |
is_teenager(20) | |
Given an uppercase letter, return the letter 3 | |
letters down. Treat the alphabet as a circle, | |
with A following Z. (...XYZABCD...). | |
(Given 'A', returns 'D'. Given 'Z', returns 'C') | |
def is_consonant(letter): | |
return letter != "A" | |
and letter != "E" | |
and letter != "I" | |
and letter != "O" | |
and letter != "U" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment