Computer Science, asked by varmalohith2112, 7 months ago

Write two functions. The first finds the average of any set of three integers. The second finds the median of any set of three integers. A median is the number in the middle when the set is sorted (for example, the median of 4, 9, 6 is 6 because if the numbers are sorted the set is (4, 6, 9)). Then call each function in the program to find the average and median of any three integers. Test your program for at least five different sets and tabulate the result.

Answers

Answered by TheArkhamKnight
0

Answer:

import numpy as np

def mean():

   numbersArray = np.array([])  //Declare an array

   for x in range(0, 3):  //Do something three times

       numbersArray = np.append(numbersArray, float(input("Enter your number: ")))  //Do this three times - add numbers to the array

   sumOfNumbers = np.sum(numbersArray)  //Add together the numbers in the array

   mean = sumOfNumbers / 3  //Divide the sum of the numbers

   print(mean)  //Print the result

def median():

   medianList = np.array([])  //Another array

   for x in range(0, 3):  //Do something three times

       medianList = np.append(medianList, float(input("Enter your number: ")))  //Again, add to the list

   print(medianList[1])  //Print the middle item of the three numbers.

   

mean()  //Call the mean function

median() //Call the median function

Explanation:

This is done in Python (I hope that's OK). (BTW, formatting for comments might be a bit weird, but feel free to remove them.) Have a nice day!

Similar questions