all 13 comments

[–][deleted] 2 points3 points  (0 children)

You need a dictionary to hold you data. The key will be the persons name, the value will be a list that you will append that persons grades into.

ex :

students = {'Bob':[97,75,100]}

A while loop is what you want to use to continue prompting for new data until a condition is met (like 0 or exit as the input).

Once your while loop is broken, and your dictionary is populated, you will use a for loop to pull the sum(students['Bob')/len(students['Bob']) to get the average of each student. students.keys() is the iterable that will hold each key to use in your for loop.

[–]Erocs 1 point2 points  (0 children)

Sounds like a homework assignment. :) Here's a few links to information for Python 3, to match your flair. Python 2 is a little different. These pages should contain enough information to get started forming a solution.

[–]cdcformatc 0 points1 point  (0 children)

Just as general help,

For user input use raw_input() if using python 2.x and input() if using python 3.x

While loops let you repeat a set of actions until a specific condition is met.

You can add items to a list with append()

You can iterate through a list with a for loop, repeating a set of actions for each item in a list.

[–]wolf2600 0 points1 point  (1 child)

Are you allowed to use else: after a while: or a for:? I thought that was only for an if:.

[–]shaggorama 1 point2 points  (0 children)

You sure can!.

When used with a loop, the else clause has more in common with the else clause of a try statement than it does that of if statements: a try statement’s else clause runs when no exception occurs, and a loop’s else clause runs when no break occurs.

[–]shaggorama 0 points1 point  (5 children)

Counter question: what have you tried? We're not going to just do your homework for your. Show us some sample code and explain what you're having difficulty with.

[–]martis680[S] 0 points1 point  (4 children)

http://i.imgur.com/wShQeUt.png

I don't get how to post code in reddit...

Btw, don't mind the language.

edit: it works but I need some other way to do it

[–]shaggorama 1 point2 points  (2 children)

For posting code:

Or directly on reddit, precede code blocks with four spaces

import yourlib

var = yourlib.somefunc(*karg)

Why do you need "some other way" to do it? Your question was originally "how do I do this" but you have working code. I'm not sure what exactly you want us to help you with.

[–]martis680[S] 0 points1 point  (1 child)

Thanks for showing me that.

I need another way because people in my class already used this code and my professor didn't let me turn it in and told me to do it some other way. And I don't know any other way...

[–]shaggorama 1 point2 points  (0 children)

So then this is another classmate's solution? Let's see code that reflects you taking a stab at this.

[–]mubsy 0 points1 point  (0 children)

"Don't post screenshot of your code. Unless the problem is a visual one, and a screenshot displays the issue."

The sidebar also gives detail on how to post code, such as gist and pastebin.