{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

mean - for n in num aTotal = int(n gTotal*= int(n#print out...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
# Author: Yeuan-Shyuan(James) Cheng # SutdentID: 301001191 # CMPT 165 Assignment 3 # mean.py # Jun 30, 2008 # print "Calculate the arithmetic and geometric mean\n" p #ask for input, and separate the number with "," and store it num = raw_input("Enter all the numbers you want to calculate(separate with ','): ").split(",") " aTotal = 0.00 #initialize the arithmetic total to 0 gTotal = 1 #initialize the geometric total to 1 g #for loop run through each number store in num #calculate the total for arithmetic or geometric
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for n in num: aTotal += int(n) gTotal *= int(n) #print out the arithmetic mean in string print "\nThe arithmetic mean is: "+ str(aTotal / len(num)) p #set nominator to 1 nominator=1 n #denominator is the lengh of num denominator = len(num) d #get the inverse cast nominator and denominator to float not int inverse = float(nominator)/float(denominator) i #print out the geometric mean in string print "\nThe geometric mean is: " + str(gTotal ** inverse) p raw_input('\nPress enter to quit.')...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online