Download presentation
Presentation is loading. Please wait.
Published byFrank Welch Modified over 9 years ago
1
Xin Liu Feb 25, 2013
2
* Compared to Arithmetic mean, or average * The Geometric Mean of 2 numbers is defined as
3
* The Geometric Mean of 3 numbers is defined as
4
* The Geometric Mean of n numbers is defined as
5
* Download data files from pages.cpsc.uca lgary.ca/~liuxi n * Improvements * Use sentinel * Use list * Check zero input # read data into a list list_data = [] while True: line = input() if line == 'end': # check sentinel break list_data.append(float(line)) # calculate the geometric mean product = 1.0 for i in range(len(list_data)): product = product * list_data[i] if len(list_data) == 0: # check zero input print("Zero input") else: product = product ** (1/len(list_data)) print("The Geometric Mean is: ", product)
6
* Math concept * The median of a list of n numbers, is the numerical value separating the higher half, from the lower half. * Calculation * Sort the numbers in increasing order * The median is * the number in the middle If n is odd * The mean of the two numbers in the middle * Examples: * The median of [0, 1, 100] is 1 * The median of [0, 1, 2, 100] is (1+2)/2 = 1.5
7
# read data into a list list_data = [] while True: line = input() if line == 'end': # check sentinel break list_data.append(float(line)) # sort the list list_data.sort() print("the input list after sorting is:"); print(list_data) # calculate the median numData = len(list_data) if numData == 0: # check zero input print("Zero input") elif numData % 2 == 1: # odd median = list_data[numData // 2] print("The median is: ", median) else: # even median = (list_data[numData // 2 - 1] + list_data[numData // 2]) / 2.0 print("The median is: ", median)
8
* Just released on John’s webpage * Due: 4pm Friday, 1 March 2013
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.