From fa1bd2037a72684e382467e187cc294fe1da4918 Mon Sep 17 00:00:00 2001 From: Citrus716 <60357364+Citrus716@users.noreply.github.com> Date: Sat, 18 Jul 2020 14:14:36 -0400 Subject: [PATCH 1/3] Added --- .../chapter11/solutions/number_mystery_1.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2_intermediate/chapter11/solutions/number_mystery_1.py diff --git a/2_intermediate/chapter11/solutions/number_mystery_1.py b/2_intermediate/chapter11/solutions/number_mystery_1.py new file mode 100644 index 00000000..5118f0a4 --- /dev/null +++ b/2_intermediate/chapter11/solutions/number_mystery_1.py @@ -0,0 +1,19 @@ +# Write a function that takes in 3 integers. Get the sum of the 3 integers. Get +# the difference between the largest integer and the smallest integer. The +# function will return the product of these two integers you got. +# +# Use this function on 1,2,3 and print it. Use this function on 5,13,7 and +# print it + +def num_mystery(first_int, second_int, third_int): + sum_of_three = first_int + second_int + third_int + largest = max(first_int, second_int, third_int) + smallest = min(first_int, second_int, third_int) + diff_ls = largest - smallest + + return sum_of_three * diff_ls + +print(num_mystery(1,2,3))#should print 12 +print(num_mystery(5,13,7))#should print 200 + + From 18e700f516da97c81efa7ffd0d1be0d5419f9fcb Mon Sep 17 00:00:00 2001 From: Lint Action Date: Sat, 18 Jul 2020 18:15:33 +0000 Subject: [PATCH 2/3] Fix code style issues with Black --- 2_intermediate/chapter11/solutions/number_mystery_1.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2_intermediate/chapter11/solutions/number_mystery_1.py b/2_intermediate/chapter11/solutions/number_mystery_1.py index 5118f0a4..a70d9087 100644 --- a/2_intermediate/chapter11/solutions/number_mystery_1.py +++ b/2_intermediate/chapter11/solutions/number_mystery_1.py @@ -5,6 +5,7 @@ # Use this function on 1,2,3 and print it. Use this function on 5,13,7 and # print it + def num_mystery(first_int, second_int, third_int): sum_of_three = first_int + second_int + third_int largest = max(first_int, second_int, third_int) @@ -13,7 +14,6 @@ def num_mystery(first_int, second_int, third_int): return sum_of_three * diff_ls -print(num_mystery(1,2,3))#should print 12 -print(num_mystery(5,13,7))#should print 200 - - + +print(num_mystery(1, 2, 3)) # should print 12 +print(num_mystery(5, 13, 7)) # should print 200 From 2eb40ae6181b201021b6c828397ac31ccb455ffc Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Sat, 18 Jul 2020 15:30:50 -0700 Subject: [PATCH 3/3] Fix style and clarify instructions --- .../chapter11/solutions/number_mystery_1.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/2_intermediate/chapter11/solutions/number_mystery_1.py b/2_intermediate/chapter11/solutions/number_mystery_1.py index a70d9087..5ec847dc 100644 --- a/2_intermediate/chapter11/solutions/number_mystery_1.py +++ b/2_intermediate/chapter11/solutions/number_mystery_1.py @@ -1,19 +1,27 @@ -# Write a function that takes in 3 integers. Get the sum of the 3 integers. Get -# the difference between the largest integer and the smallest integer. The -# function will return the product of these two integers you got. +# Number Mystery 1 +# Write a function called num_mystery that takes in 3 integers. +# The function should calculate the sum of the 3 integers and +# the difference between the largest integer and the smallest integer. +# The function should return the product of these two integers you calculated. # -# Use this function on 1,2,3 and print it. Use this function on 5,13,7 and -# print it +# Hint: You may find it useful to use the max() and min() functions. +# +# Use the num_mystery function on 1, 2, 3 and print the result. +# Use the num_mystery function on 5, 13, 7 and print the result. def num_mystery(first_int, second_int, third_int): + # calculate the sum of the 3 numbers sum_of_three = first_int + second_int + third_int + + # calculate the difference between the max and min largest = max(first_int, second_int, third_int) smallest = min(first_int, second_int, third_int) - diff_ls = largest - smallest + difference = largest - smallest - return sum_of_three * diff_ls + # return the product + return sum_of_three * difference -print(num_mystery(1, 2, 3)) # should print 12 -print(num_mystery(5, 13, 7)) # should print 200 +print(num_mystery(1, 2, 3)) # prints 12 +print(num_mystery(5, 13, 7)) # prints 200