標題: Help with writing python math programs [打印本頁] 作者: Intelstan 時間: 2008-7-1 08:58 標題: Help with writing python math programs
How do you write a code for calculating arithmetic and geometric mean using python? I want to make it so that users can input as many numbers as they want to calculate.
I only got to this far (but it's not correct):
print "This is a program that calculates arithmetic mean."
x = int( raw_input("Please enter the first number: ") )
y = int( raw_input("Please enter the second number: ") )
z = int( raw_input("Please enter the third number: ") )
print "The arithmetic mean of the three numbers is", (x+y+z)/3, "."作者: p51dray 時間: 2008-7-1 20:50
uh use an array?
I don't know python but the general strategy is to use a dynamic array whose size increases by one as the user enters in the numbers.
Then you just loop through the array to calculate the mean.