Friday 15 August 2014

python - calculating mean doesn't work -


Generates code: You gave me the following number: 1 2 3 When the mean is calculated, it equals 0 I need to answer 2

  def get_numbers (): print "When you are finished, enter any number" my_list = [] while true: number = raw_input () if number! = "Q": num = int (number) my_list.append (num) Other: my_list def add (): the_list = get_numbers () total = 0 in i_list: total = total * i total = total / lane (The_list) print "You gave me the following number:", in_list for x: y = str (x) print y, print ".", "When computed, this is equal", total, "." The main problem you have to do is:  

P>

 < Code> total = 0 in i_list: total = total + i total = float (total) / lane (the_list)  

You do not need to add numbers

There are several other problems with your code:

  • The name addition does not actually say anything about what it does
  • You might want to separate I / O (user inquiries) from computation (Calculate the mean).

This version fixes those issues:

  def get_numbers (): print "Enter any number, when you're finished q" My_list = [] while true: number = raw_input () if number! = "Q": num = int (number) my_list.append (num) Other: return my_l IT Diff Mean (L): Total = 0 i in L: Total = Total + IR = Float (Total) / Lane (L) Returns Rdf (main): The_list = get_numbers () Print "You gave me the following number:", in the list for x: y = str (x) print y, print ".", "When it means that It is equal to ", meaning (the_list),". "Main ()  

No comments:

Post a Comment