Posted on

You are working on problem set Unit 4 Task Coding Part 1 OPause medianof3 0 LanguageType

You are working on problem set: Unit 4 - Task| Coding Part 1 (Pause) median_of_3 Language/Type: Python Errors: if/else return string The following function attempts to return the median (middle) of three integer values, but it contains logic errors. In what cases does the function return an incorrect result? How can the code be fixed? Determine what is wrong with the code, and submit a corrected version that works properly. def median_of_3(n1, n2, n3): if n1 < n2: if n2 < n3: return n2 else: return n3 else: if n1 < n3: return n1 else: return n3

You are working on problem set:
Unit 4 – Task| Coding Part 1 (Pause) median_of_3
Language/Type: Python
Errors: if/else return string

The following function attempts to return the median (middle) of three integer values, but it contains logic errors.

In what cases does the function return an incorrect result?
How can the code be fixed?
Determine what is wrong with the code, and submit a corrected version that works properly.

def median_of_3(n1, n2, n3):
if n1 < n2: if n2 < n3: return n2 else: return n3 else: if n1 < n3: return n1 else: return n3


 
Solved By Verified
Study Co-Pilot All Study Co-Pilots are evaluated by Gotit Pro as an expert in their subject area.

 
Instant
Download

Student review: (5 ratings) 5 out of 5 people found this solution helpful.