## Help with calculating the average of variables

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

### Help with calculating the average of variables

So, I'm pretty new to python, but I've got an assignment in which I must calculate the average of a range of variables given by the user. Variables are supposed to be grades.
I've got:

for c in range (0,50)
Grade = input ("What is the student's grade?')

How do I get the average of all the user''s inputs?
Should I use import statistic mean?

Also, how could I get how many graded are below 50 and above or equal to 50

Thanks!
Last edited by micseydel on Wed Sep 28, 2016 3:57 pm, edited 1 time in total.
Reason: Initial post lock.
NotASeagull

Posts: 1
Joined: Wed Sep 28, 2016 3:03 pm

### Re: Help with calculating the average of variables

How would you do it without a computer? Try to split the problem into many simple steps. Then solve these steps one by one.

No, you do not need that import. Your current solution will forget all inputs, whenever it gets the next one. Do you already know about lists in python?
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

### Re: Help with calculating the average of variables

Kebap wrote:How would you do it without a computer? Try to split the problem into many simple steps. Then solve these steps one by one.

No, you do not need that import. Your current solution will forget all inputs, whenever it gets the next one. Do you already know about lists in python?

You don't need lists here. You need to know the current total and how many grades you have included in it.
This forum has been moved to http://python-forum.io/. See you there.

Ofnuts

Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

### Re: Help with calculating the average of variables

Ofnuts wrote:You don't need lists here. You need to know the current total and how many grades you have included in it.

if the number of scores is large and/or wide ranging, summing them in sorted order is a good idea. therefore collecting the scores in a list (or maybe OrderedDict) is a good idea.
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016. This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
Skaperen

Posts: 267
Joined: Tue Apr 07, 2015 9:58 am
Location: Wheeling WV USA

### Re: Help with calculating the average of variables

I didn't say there were needed, I asked a question about which tools were known and allowed, as in trying to start a conversation.
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

### Re: Help with calculating the average of variables

Presuming the student cannot import anything, use lists or dictionary's, etc., it would still be a simple matter to determine the average score and how many of those were below 50 and how many were equal or greater than 50. I have to say, given the students example, entering 50 scores would become rather boring after entering say 10 scores
THIS FORUM WILL BE CLOSING OCT 1, 2016. PLEASE STOP BY AND REGISTER AT THE NEW LOCATION
http://python-forum.io

sparkz_alot

Posts: 269
Joined: Sat Dec 06, 2014 2:55 pm
Location: US

### Re: Help with calculating the average of variables

NotASeagull wrote:So, I'm pretty new to python, but I've got an assignment in which I must calculate the average of a range of variables given by the user. Variables are supposed to be grades.
I've got:

for c in range (0,50)
Grade = input ("What is the student's grade?')

How do I get the average of all the user''s inputs?
Should I use import statistic mean?

Also, how could I get how many graded are below 50 and above or equal to 50

Thanks!

Looking at your post, you say you need variables, so how many variables do you need? (Hint: the number is contained in your post).

Again looking at your post, you can see that you know how many grades there are and what those grades are. How would you find the average grade?

One piece of advice I would give is the line:
Code: Select all
`Grade = input ("What is the student's grade?)`

is going to return a 'string' value. Since the rest of your script will be dealing with numbers, how can you convert this from a 'string' value to a 'numerical' value?

Let us know how you progress.
THIS FORUM WILL BE CLOSING OCT 1, 2016. PLEASE STOP BY AND REGISTER AT THE NEW LOCATION
http://python-forum.io

sparkz_alot

Posts: 269
Joined: Sat Dec 06, 2014 2:55 pm
Location: US

### Re: Help with calculating the average of variables

Skaperen wrote:
Ofnuts wrote:You don't need lists here. You need to know the current total and how many grades you have included in it.

if the number of scores is large and/or wide ranging, summing them in sorted order is a good idea. therefore collecting the scores in a list (or maybe OrderedDict) is a good idea.

Uh? With my solution you just add N numbers, with you solution, you create a whole OrderedDict before adding numbers. How can that be faster? (incidentally, in the case at hand, all number are keyboarded in, so you'll be lucky if you have more that 10).
This forum has been moved to http://python-forum.io/. See you there.

Ofnuts

Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

### Who is online

Users browsing this forum: No registered users and 4 guests