Question:
Python Code: Allow input for Name, Age, Gender: allow input of gender: average the age = female average and male averages: allow break?
James
2018-01-18 15:04:10 UTC
Python Code: Allow input for Name, Age, Gender: allow input of gender: average the age = female average and male averages: allow break?
Four answers:
Huh
2018-01-19 04:02:50 UTC
So this assignment is hard, huh!? Talk to me when you have to reverse a linked list.
?
2018-01-18 19:33:53 UTC
I would say all of your answers were completely funny but since this is an assignment and I haven't the foggiest idea of where to even begin... its not funny.
husoski
2018-01-18 15:38:18 UTC
If the whole program seems too much to write, it probably is. Start with a part you can understand; code that up and get it working. If you have trouble with input, just write test input as assignment statements and write the code that does the averaging. If the list handling and averaging code is a mystery, write the input code.



I'd suggest starting with the input. Write a program that uses the input() function (in Python 2.x, use raw_input() instead) three times to get values for name, age and gender of one person. Those will all be strings, so you'll use float() or int() convert the age to a number. Print out the results.



Next, modify that code to add the information to a list, or perhaps to separate lists. You'll need to add code to initialize the list(s), a loop around the input code (now indented), and a way to stop the input (name=='stop', looping for a specific number of individuals, etc.)



Print out the lists.



Now you can add code to loop through that data and compute averages. Maybe you start with a loop for males and another loop for females; maybe you make one loop with if/else on gender inside the loop. You have choices.



This is the classic way of dealing with a program too complex to write: Break it down into manageable subprograms. It used to be called "stepwise refinement", and some of us still use that term. The notion is far older than computer programming, though. For most of mathematical history, the primary way to solve a complicated mathematical problem is to transform it into one or more simpler problems.
2018-01-18 15:29:49 UTC
Hi so you have to set up the parameters.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...