Writing your own functions (3/5)
Task
Swipe to start coding
Define a function sum_two_gr
with three arguments returning the sum of the greatest two.
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
# define a function
def sum_two_gr(a, b, c):
if min(a, b, c) == a:
return b + c
elif min(a, b, c) == b:
return a + c
else:
return a + b
# test new function
print(sum_two_gr(1, 2, 3))
print(sum_two_gr(10, 15, 5))
print(sum_two_gr(20, 10, 30))
Everything was clear?
Thanks for your feedback!
Section 7. Chapter 4
99
1
2
3
4
5
6
7
8
9
10
11
12
13
# define a function
def sum_two_gr(a, b, c):
if min(a, b, c) == a:
return b + c
elif _ _ _:
return _ _ _
else:
return _ _ _
# test new function
print(sum_two_gr(1, 2, 3))
print(sum_two_gr(10, 15, 5))
print(sum_two_gr(20, 10, 30))
Ask AI
Ask anything or try one of the suggested questions to begin our chat