1.

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.

Answer»

import numpy as npdef 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 resultdef 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 functionmedian() //Call the median functionExplanation: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!



Discussion

No Comment Found