Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Writing your own functions (3/5) | Functions
Learn Python from Scratch

book
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

# 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?

How can we improve it?

Thanks for your feedback!

Section 7. Chapter 4
# 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

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

We use cookies to make your experience better!
some-alt