# 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)
当我使用上面的这三个打印运行它时,它工作得非常好,但是当尝试不同的打印时,输出不正确。例如,当我尝试 print median(3,2,1) 时,输出为 1,这是一个不正确的答案。这段代码有什么问题,我该如何解决?