# Define a procedure, median, that takes three
# numbers as its inputs, and returns the median
# of the three numbers.
# Make sure your procedure has a return statement.
def bigger(b,c):
if b > c:
return b
else:
return c
# if b is returned, then b >c
# if c is returned, then c > b
def biggest(a,b,c):
return bigger(a,bigger(b,c))
def median(a,b,c):
if biggest(a,b,c) == c and bigger(a,b) ==a:
# c > b and c > a
# a > b
return a
elif biggest(a,b,c) == c and bigger(a,b)==b:
#
return b
else:
return c
print(median(1,2,3))
#>>> 2 (correct)
print(median(9,3,6))
#>>> 6 (correct)
print(median(7,8,7))
#>>> 7 (correct)
print(median(3,2,1)
#>>> 1 (incorrect)
上記の 3 つのプリントで実行すると問題なく動作しますが、別のプリントを試すと出力が正しくありません。たとえば、 print median(3,2,1) を試したとき、出力は 1 でした。これは間違った答えです。このコードの問題は何ですか?どうすれば修正できますか?