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
Write the following Python script: Write a function called linsolve() that will be useful in categorizing...
Write the following Python script: Write a function called linsolve() that will be useful in categorizing and solving linear algebra problems. The function will have up to three parameters: • A required 2D array representing the coefficient matrix of a linear algebra equation, • A required 1D or 2D array representing the right-side constants of a linear algebra equations, and • An optional parameter used to determine which condition number to use in determining the condition of the system. The...
Which one of the following expressions evaluates to True? Select one: 5 > 1 and 1...
Which one of the following expressions evaluates to True? Select one: 5 > 1 and 1 == 5 5 > 9 or 2 < 0 or not 42 > 1 not 8 < 5 and not 10 == 3 not (15 == 15 or 15 < 0) 36 == 35 or 35 > 2 and 35 < 0
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 python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a...
Write a python function called HackCaesar with the following requirements: def hack_caesar(cyphertext): ‘’’ cyphertext is a text encoded using Caesars encryption. The encryption key is unknown. The function returns the correct encryption key. Hint: Use the function we wrote was called caesar(c, key) and could encode a single character. # YOUR CODE GOES HERE def is_odd(n): return n%2 == 1 def caesar(c, key): """ Encrypts a lower case character c using key Example: if c = "a" and key=3 then...
Write a small section of Python code that defines a function called check_even(value) - the function...
Write a small section of Python code that defines a function called check_even(value) - the function takes a numerical value as input and returns True or False based on whether the provided argument is divisible by 2 (i.e. is it odd or is it even). If the argument provided is not a number (as determined by built-in the isdigit() function - which only works on string data) then rather than crashing, the function should raise an exception which is caught...
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".
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,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT