Question

In: Computer Science

#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...

#Python

5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:

  1. Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage.
  2. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average.
  3. Print the largest value among x, y, and z.
  4. Print the minimum value of x, y, y.

>>> 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

Solutions

Expert Solution

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:


Related Solutions

5. Given the following declarations and assignments, what do these expressions evaluate to? int a1[10] =...
5. Given the following declarations and assignments, what do these expressions evaluate to? int a1[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; int *p1, *p2; p1 = a1+3; p2 = &a1[2]; (a) *(a1+4) (b) a1[3] (c) *p1 (d) *(p1+5) (e) p1[-2] (f) *(a1+2) (g) a1[6] (h) *p2 (i) *(p2+3) (j) p2[-1]
Lab 7. Boolean Expressions a) Write a program that evaluates the following expressions. Assign reasonable values...
Lab 7. Boolean Expressions a) Write a program that evaluates the following expressions. Assign reasonable values to the variables. Print the results. a<b≥c , √a−7 b2 ≠c , d∨e∧f , a<b∨¬d ∧means and, ∨means inclusive or, ¬ means not. b) Write a program that asks a user whether he or she wants to become a Java programmer and determines if the user typed “yes” (Print true if yes and false otherwise.) Don't use the if statement here
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
This is python: #Write a function called count_positive_evens. This function #should take as input a list...
This is python: #Write a function called count_positive_evens. This function #should take as input a list of integers, and return as #output a single integer. The number the function returns #should be the count of numbers from the list that were both #positive and even. # #For example: # # count_positive_evens([5, 7, 9, 8, -1, -2, -3]) -> 1 # count_positive_evens([2, 4, 6, 8, 10, 12, 15]) -> 6 # count_positive_evens([-2, -4, -6, -8, -10, 1]) -> 0 # #0...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
In python of Jupiter notebook Write a python function called trng that takes three numbers x,...
In python of Jupiter notebook Write a python function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangleotherwise). Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y...
Write a program in Python to practice evaluating some logical expressions and determine whether the expressions...
Write a program in Python to practice evaluating some logical expressions and determine whether the expressions are equivalent. Read in a 0 or 1 integer value for each of the following variables: A, B, C, and D. Use an if…else statement to change the 0 and 1 integer values into True and False Boolean values. Booleans in Python have to have this capitalization (True/False, not true/false or TRUE/FALSE) and shouldn’t contain double quotes (which makes them a String instead of...
Write a class Lab7 that reads and evaluates postfix expressions contained in a file. Each line...
Write a class Lab7 that reads and evaluates postfix expressions contained in a file. Each line of the file contains a postfix expression with integers as operands and ‘+’, ‘-’, ‘*’ and ‘/’ as operators. Consecutive operands and operators are separated by spaces. Note the following requirements for the lab: • The main method in Lab7.java should do the following. 1. ask the user for the name of the file containing the expressions, 2. for each line of the file,...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
use python to solve Write a function called word_chain that repeatedly asks the user for a...
use python to solve Write a function called word_chain that repeatedly asks the user for a word until either (1) the user has entered ten words, or (2) the user types nothing and presses enter. Each time the user enters an actual word, your program should print all the words entered so far, in one long chain. For example, if the user just typed "orange", and the user has already entered "apple" and "banana", your program should print "applebananaorange" before...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT