473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Creating a menu based program based on a list

I am having issues creating a menu-driven program that should accept integers and calculate the mean and median values and display them. I'm not having trouble calculating the Mean or Median, but I am having trouble with configuring the list into the program.

Expand|Select|Wrap|Line Numbers
  1. #Main
  2. def main():
  3.     array = [] #this would be the list, but what do i do with it?
  4.     choice = displayMenu()
  5.     while choice != '4':
  6.         if choice == '1':
  7.             addNum()
  8.         if choice == '2':
  9.             calcMean()
  10.         if choice == '3':
  11.             displayMedian()
  12.         choice = displayMenu()
  13.  
Now, this is my main function. I'm not completely sure what to do with the list. The next part would be the displayMenu() function, but that's correct so I'm not going to post it. However, next would be option number one, the addNum() function.

Expand|Select|Wrap|Line Numbers
  1. #adding numbers to the list
  2. def addNum(): #how do I get it to return to the list in main?
  3.     number = raw_input("Enter number: ")
  4.     array.append(number)
  5.  
I feel like I'm close to getting this correct, but at the same time I'm completely stuck and don't know what to do.

Any help, advice, and input would be greatly appreciated. thank you
Nov 7 '10 #1
2 18863
dwblas
626 Expert 512MB
I am having trouble with configuring the list into the program.
I have no idea what this means, but generally speaking, you haven't returned any thing from the function. You have to return a variable from a function as, any changes that are made in the function stay in the function, to alter the Vegas phrase, unless you return the value to some variable outside the function. This is very basic stuff, which you should know, so instead of coding yourself start with one of the online books here or here.
Expand|Select|Wrap|Line Numbers
  1. ##   see the Python style guide http://www.python.org/dev/peps/pep-0008/
  2. ##   function and variable names are all lower case
  3. def add_num(array): #how do I get it to return to the list in main?
  4.     number = raw_input("Enter number: ")
  5.     array.append(number)
  6.     return array
  7.  
  8. ##   calling main() from "if __name__ == '__main__' is redundant (unnecessary)
  9. ##   and considered bad style as it is not obvious that this code runs when you
  10. ##   run this program (as opposed to executing a function from another program).
  11. if __name__ == '__main__:
  12.     array = [] #this would be the list, but what do i do with it?
  13.     choice = displayMenu()
  14.     while choice != '4':
  15.         if choice == '1':
  16.             array = add_num(array)
  17.             print array
  18.         if choice == '2':
  19.             calcMean()
  20.         if choice == '3':
  21.             displayMedian()
  22.         choice = displayMenu() 
Nov 7 '10 #2
Thank you very much. I think i was just so stressed from everything else that I missed something so simple.
Nov 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Will Stuyvesant | last post by:
I never used the popen or popen2 libraries but it is my understanding that they can capture the output of console based programs. Is it also possible to send keystrokes to console base programs? ...
1
by: Anoj Kumar | last post by:
Hi Guys! How to capture output of a console based program and display it on Windows Forms applcation. Thx Anoj Kumar
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
2
by: deja | last post by:
Hello, I am creating an a to z list - basically a count of all results that start with the letter "A", "B", "C" .... and so on. I am pretty poor at SQL so I am sure some brains out there can...
2
by: Gary Wessle | last post by:
Hi I need help organizing this program in the right way. I included the code below which compiles and runs and gives the desired effect to a certain point, but I don't know what the next step...
1
by: neeleshsingh12444 | last post by:
Hi I am new to this area i am working on a project (based on C)which need to select a text file from a directory . I am selecting the file by giving the path in the console window but my project...
5
by: Greg Corradini | last post by:
Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
2
by: elizann | last post by:
How do i enable several groups of radio buttons based on a list box selection for eg. function checkwork(){ var X = document.form2.notworking.value; if(X=="No"){ ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.