|
1 | | -# Write a function that takes in 3 integers. Get the sum of the 3 integers. Get |
2 | | -# the difference between the largest integer and the smallest integer. The |
3 | | -# function will return the product of these two integers you got. |
| 1 | +# Number Mystery 1 |
| 2 | +# Write a function called num_mystery that takes in 3 integers. |
| 3 | +# The function should calculate the sum of the 3 integers and |
| 4 | +# the difference between the largest integer and the smallest integer. |
| 5 | +# The function should return the product of these two integers you calculated. |
4 | 6 | # |
5 | | -# Use this function on 1,2,3 and print it. Use this function on 5,13,7 and |
6 | | -# print it |
| 7 | +# Hint: You may find it useful to use the max() and min() functions. |
| 8 | +# |
| 9 | +# Use the num_mystery function on 1, 2, 3 and print the result. |
| 10 | +# Use the num_mystery function on 5, 13, 7 and print the result. |
7 | 11 |
|
8 | 12 |
|
9 | 13 | def num_mystery(first_int, second_int, third_int): |
| 14 | + # calculate the sum of the 3 numbers |
10 | 15 | sum_of_three = first_int + second_int + third_int |
| 16 | + |
| 17 | + # calculate the difference between the max and min |
11 | 18 | largest = max(first_int, second_int, third_int) |
12 | 19 | smallest = min(first_int, second_int, third_int) |
13 | | - diff_ls = largest - smallest |
| 20 | + difference = largest - smallest |
14 | 21 |
|
15 | | - return sum_of_three * diff_ls |
| 22 | + # return the product |
| 23 | + return sum_of_three * difference |
16 | 24 |
|
17 | 25 |
|
18 | | -print(num_mystery(1, 2, 3)) # should print 12 |
19 | | -print(num_mystery(5, 13, 7)) # should print 200 |
| 26 | +print(num_mystery(1, 2, 3)) # prints 12 |
| 27 | +print(num_mystery(5, 13, 7)) # prints 200 |
0 commit comments