Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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