diff --git a/CodeRepo/Functions b/CodeRepo/Functions new file mode 100644 index 0000000..50ee1a6 --- /dev/null +++ b/CodeRepo/Functions @@ -0,0 +1,74 @@ +def square(n): + """Returns the square of a number.""" + squared = n ** 2 + print "%d squared is %d." % (n, squared) + return squared + +# Call the square function on line 10! Make sure to +# include the number 10 between the parentheses. +square(6) +----------------------------------------------------------------------------------------------- +def power(base, exponent): # Add your parameters here! + result = base ** exponent + print "%d to the power of %d is %d." % (base, exponent, result) + +power(7, 4) # Add your arguments here! +----------------------------------------------------------------------------------------------- +def one_good_turn(n): + return n + 1 + +def deserves_another(n): + #Change the body of deserves_another so that it always adds 2 to the output of one_good_turn. + return one_good_turn(n) + 2 +----------------------------------------------------------------------------------------------- +def cube(number): + return number ** 3 + +def by_three(number): + if cube(number) % 3 == 0: + return cube(number) + else: + return False +----------------------------------------------------------------------------------------------- +# Ask Python to print sqrt(25) +import math +print math.sqrt(25) +# Import *just* the sqrt function from math +from math import sqrt +print sqrt(25) +# Import *everything* from the math module +from math import * +----------------------------------------------------------------------------------------------- +def biggest_number(*args): + print max(args) + return max(args) + +def smallest_number(*args): + print min(args) + return min(args) + +def distance_from_zero(arg): + print abs(arg) + return abs(arg) + +biggest_number(-10, -5, 99,5, 10) +smallest_number(-10,-88, -5, 5, 10) +distance_from_zero(-10) +----------------------------------------------------------------------------------------------- +# Check the value of "s" +def shut_down(s): + if s == "yes": + return "Shutting down" + elif s == "no": + return "Shutdown aborted" + else: + return "Sorry" +----------------------------------------------------------------------------------------------- +# Built-In Functions +def distance_from_zero(t): + if type(t) == int or type(t) == float: + print abs(t) + else: + print "Nope" + +distance_from_zero(-6.6) diff --git a/CodeRepo/Vacation b/CodeRepo/Vacation new file mode 100644 index 0000000..8d05534 --- /dev/null +++ b/CodeRepo/Vacation @@ -0,0 +1,25 @@ +def hotel_cost(nights): + return 140 * nights +# ================================ +def plane_ride_cost(city): + if city == "Charlotte": + return 183 + elif city == "Tampa": + return 220 + elif city == "Pittsburgh": + return 222 + elif city == "Los Angeles": + return 475 +# =============================== +def rental_car_cost(days): + cost = days * 40 + if days >= 7: + cost -= 50 + elif days >= 3: + cost -= 20 + return cost +# ================================== +def trip_cost(city, days, spending_money): + return hotel_cost(days - 1) + plane_ride_cost(city) + rental_car_cost(days) + spending_money +# ================================== +print trip_cost("Los Angeles", 5, 600)