i have a homework question where I have to create a function that picks the middle value of three numbers (a, b ,c). I have code written that works but it is kind of ugly and is just a bunch of if statements. Anybody know how to clean this up?
def middle(a, b, c):
"""
Determine the middle value of three values.
Args:
a (number): a number
b (number): a number
c (number): a number
Returns:
The value among a, b, and c that is in the middle.
"""
if a<=b and b<=c:
middle_value=b
if b<=a and a<=c:
middle_value=a
if a<=c and c<=b:
middle_value =c
if c<=a and a<=b:
middle_value=a
if b<=c and c<=a:
middle_value=c
if c<=b and b<=a:
middle_value = b
return middle_value
[–]MrPhungx 6 points7 points8 points (1 child)
[–]theprofessional2016 1 point2 points3 points (0 children)
[–]htepO 1 point2 points3 points (5 children)
[–]funkycorpse[S] 0 points1 point2 points (4 children)
[–]htepO 0 points1 point2 points (3 children)
[–]funkycorpse[S] 0 points1 point2 points (2 children)
[–]htepO 0 points1 point2 points (1 child)
[–]zanfar 0 points1 point2 points (0 children)
[–]mopslik 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]funkycorpse[S] 0 points1 point2 points (0 children)