previous problem: Write a Python program that, given three numbers, x, y, and z,
ID: 3832519 • Letter: P
Question
previous problem: Write a Python program that, given three numbers, x, y, and z, uses nested if statements to print the smallest value among the three. Use the following algorithm: the outermost if tests if x is less than y. If x is less than y then an inner if compares x and z to pick the smallest value. If x was not less than y, then an inner if compares y with z to pick the smallest.
Write a Python program that solves the same problem as the last using a different algorithm that does not use nested ifs: use two if/else statements, one following the other. The first if compares x and y and stores the smallest value in a variable named min, the second if compares min with z to pick the smallest overall.
Explanation / Answer
def min(x, y, z):
smallest = x
if y < smallest:
smallest = y
if z < smallest:
smallest = z
return smallest
# code link: https://paste.ee/p/ibDHd
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.