Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

paul99santos

Hello I have a simple problem here, I wanted to make a function that will compute the average (adding the numbers and dividing it by the count). my functions seems to display the wrong result, can you help me put comments on my source code what I did wrong and explain please? Thank you so much for you time. #average1.py def main(): n = input("How many numbers do you have?") sum = 0.0 for i in range(n): x = input("Enter a number: ") sum = sum + x print "\n The average of the number is ", sum/n -------------------------------------------------------- Example: This is the result when I call the function main() -------------------------------------------------------- How many numbers do you have?5 Enter a number: 1 The average of the number is 0.2 Enter a number: 2 The average of the number is 0.6 Enter a number: 3 The average of the number is 1.2 Enter a number: 4 The average of the number is 2.0 Enter a number: 5 The average of the number is 3.0 --------------------------------------------------------- I want the the print ---> "\n The average of the number is ", sum/n <---- to appear only once.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. bwCA
    Best Response
    You've already chosen the best response.
    Medals 1

    http://pastebin.com/5nrSEteB looks like it works to me

    • 2 years ago
  2. paul99santos
    Best Response
    You've already chosen the best response.
    Medals 0

    But I want the the print ---> "\n The average of the number is ", sum/n <---- to appear only once.

    • 2 years ago
  3. bwCA
    Best Response
    You've already chosen the best response.
    Medals 1

    ahhh - move it outside of the for loop

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.