From 8d9df997355eaa3fcef227a9730dfd463a78473f Mon Sep 17 00:00:00 2001 From: Darcula <37351246+MeatStack@users.noreply.github.com> Date: Sun, 29 Jul 2018 00:38:43 +1200 Subject: [PATCH 1/5] Function Examples --- CodeRepo/Functions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CodeRepo/Functions diff --git a/CodeRepo/Functions b/CodeRepo/Functions new file mode 100644 index 0000000..e4e9200 --- /dev/null +++ b/CodeRepo/Functions @@ -0,0 +1,15 @@ +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! From 91d75c78a0ea0488741a589162bbf2d246d0f262 Mon Sep 17 00:00:00 2001 From: Darcula <37351246+MeatStack@users.noreply.github.com> Date: Sun, 29 Jul 2018 20:42:58 +1200 Subject: [PATCH 2/5] Update Functions --- CodeRepo/Functions | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/CodeRepo/Functions b/CodeRepo/Functions index e4e9200..0ce65b0 100644 --- a/CodeRepo/Functions +++ b/CodeRepo/Functions @@ -7,9 +7,34 @@ def square(n): # 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 * From 0ad3fa4ce6e121b34941a58b0facd4d1a9de25f1 Mon Sep 17 00:00:00 2001 From: Darcula <37351246+MeatStack@users.noreply.github.com> Date: Mon, 30 Jul 2018 22:49:51 +1200 Subject: [PATCH 3/5] Update Functions --- CodeRepo/Functions | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CodeRepo/Functions b/CodeRepo/Functions index 0ce65b0..e05d112 100644 --- a/CodeRepo/Functions +++ b/CodeRepo/Functions @@ -38,3 +38,19 @@ 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) From 3bdb88be2169710332090e042213c0a7640c0cb0 Mon Sep 17 00:00:00 2001 From: Darcula <37351246+MeatStack@users.noreply.github.com> Date: Tue, 31 Jul 2018 22:07:27 +1200 Subject: [PATCH 4/5] FunctionsReview --- CodeRepo/Functions | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CodeRepo/Functions b/CodeRepo/Functions index e05d112..50ee1a6 100644 --- a/CodeRepo/Functions +++ b/CodeRepo/Functions @@ -54,3 +54,21 @@ def distance_from_zero(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) From b159416b90df9e7b078714b8ceb6cc658b17cfd2 Mon Sep 17 00:00:00 2001 From: Darcula <37351246+MeatStack@users.noreply.github.com> Date: Thu, 23 Aug 2018 10:46:14 +1200 Subject: [PATCH 5/5] Create Vacation --- CodeRepo/Vacation | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 CodeRepo/Vacation 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)