1,105,450 Community Members

Help with Max, Min, Avg program

Member Avatar
tucker001
Newbie Poster
3 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I need to make an interactive program in Python that will start by asking the user to enter a list of numbers and then it will display the following menu.

1-Find The Maximum
2-Find The Minimum
3-Find The Average
4-Exit
Please Enter Your selection

Your program will accept a number from the user and perform the task corresponding to that number. After performing the required task, the program will continue to ask to perform other tasks and display the menu. This program will end only when the user enters 4.

Member Avatar
Ene Uran
Posting Virtuoso
1,822 posts since Aug 2005
Reputation Points: 610 [?]
Q&As Helped to Solve: 278 [?]
Skill Endorsements: 10 [?]
 
0
 

We will not do your homework for you. Show us an effort first, if you have problems we can help.

Member Avatar
tucker001
Newbie Poster
3 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

We will not do your homework for you. Show us an effort first, if you have problems we can help.

Here's what I have.

def main ():
    sum=0.0
    count=0
    x = input("Enter a number")
     
     for i in range(x):
         n = input ("Enter a number")
         sum = sum + n
    print "\nThe average of the numbers is",sum / n

for i in range(99):   # need to read 99 more numbers and update the min if we read a number smaller than current value of min
       num = input("Enter next number: ")
       sum += num
       if num < min:
             min = num

for i in range(99):   # need to read 99 more numbers and update the min if we read a number smaller than current value of min
       num = input("Enter next number: ")
       sum += num
       if num > min:
             max = num
print "The smallest number was %f." % min
print 'The average is %f.' % (sum/100.0)

I have awhole lot of errors thought, plus I don't know how to make the box.

Member Avatar
griswolf
Veteran Poster
1,144 posts since Apr 2010
Reputation Points: 303 [?]
Q&As Helped to Solve: 264 [?]
Skill Endorsements: 3 [?]
 
0
 

You will be well served to think about the program flow first. Here are some questions whose answers may help you write the code you need.

  • How does the program know how many numbers to work with?
    • is the number specified by interaction?
    • is the number specified in the code?
  • How is the data made available?
    • Is it entered by the user? If so: one number at a time? (seems awkward)
    • Is it in a file somewhere? If so, how does the program know which file?
    • Is it hard coded in the program text?
  • Assuming the data is not hard coded, how do I handle it?
    • Do I read it into a data structure, then work with that structure?
    • Do I handle each item as it is seen, saving only the needed information?
  • How are the results given to the user?
    • Written to the console?
    • Written to a file?
    • In a GUI of some kind?
Member Avatar
pyTony
pyMod
6,104 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

I do not see requirement of writing your own sum, min and max; so you better concentrate finding better system of taking any number of user input. Do not worry about maths if you are really allowed to use standard functions, but input values to list by apppend method. You should take numbers until empty line or 'q', I suggest.

Member Avatar
predator78
Junior Poster
168 posts since Sep 2008
Reputation Points: 22 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
0
 

I see some nice keywords in the question....

I need to make an interactive program in Python that will start by asking the user to enter a list of numbers and then it will display the following menu.

1-Find The Maximum -- seem like some functions
2-Find The Minimum
3-Find The Average
4-Exit
Please Enter Your selection

Your program will accept a number from the user and perform the task corresponding to that number. After performing the required task, the program will continue to ask to perform other tasks and display the menu. This program will end only when the user enters 4.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article