In: Computer Science
#Python
5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:
>>> evaluate()
Enter a number for x: 3
Enter a number for y: 3
Enter a number for z: 4.5
You have entered x = 3 , y = 3 , z = 4.5
Enter what you think the average of x, y, and z is: 3.5
Your average is correct.
The maximum value of x, y, and z = 4.5
The min value of x, y, and z = 3
>>> evaluate()
Enter a number for x: 3
Enter a number for y: 3
Enter a number for z: 4
You have entered x = 3 , y = 3 , z = 4
Enter what you think the average of x, y, and z is: 4.5
Your average is not correct
The correct average is: 3.3333333333333335
The maximum value of x, y, and z = 4
The min value of x, y, and z = 3
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
def evaluate():
# read the 3 numbers x,y,z.
x = float(input('Enter a number for x: '))
y = float(input('Enter a number for y: '))
z = float(input('Enter a number for z: '))
# Print the numbers entered
print(f'You have entered x = {x}, y = {y}, z = {z}')
# Ask for average
myAverage = float(input('Enter what you think the average of x, y, and z is: '))
# Calculate the actual average.
actualAverage = (x + y + z) / 3
# Check for correctness
if myAverage == actualAverage:
print('Your average is correct.')
else:
print('Your average is not correct.')
print('\tThe correct average is: ', actualAverage)
# Print the max and min values
print('The maximum value of x, y, and z = ', max(x, y, z))
print('The min value of x, y, and z = ', min(x, y, z))
# Call the function here
evaluate()
===========
OUTPUT: