18.0k views
0 votes
Assume you have input three unique (they all have different values) values into

variables named x, y, and z. Write one or more if statements in python that determine and
print the value of the largest of these three. NO using lists, built-in functions like max(), etc.
You must do this "by hand", you must compare these variables using binary relational
operators. That just means you are comparing two values at a time, like x > y. Do not use
the three part comparison operator!

User Shijie Xu
by
8.4k points

1 Answer

6 votes

Final answer:

To find the largest of three unique numbers x, y, and z in Python, use nested if and else statements to compare them pairwise and print the largest value.

Step-by-step explanation:

To determine the largest value among three unique variables x, y, and z using Python, you can use a series of if and else statements to compare the variables two at a time and print out the largest value. Here is a simple way to code this:

if x > y:
if x > z:
print('The largest value is:', x)
else:
print('The largest value is:', z)
else:
if y > z:
print('The largest value is:', y)
else:
print('The largest value is:', z)

This code snippet effectively compares each variable pairwise to determine which is the largest without using any lists or built-in functions such as max(). It adheres to the condition of using binary relational operators to compare two values at a time, like x > y.

User MuiBienCarlota
by
8.8k points

No related questions found