Hello Guys, its my first few months on progamming, love the course but things are abit confusing at the moment, i have this assignment below, pls i will appreciate if anyone can help me out.

Write a program to accept a number of scores from a user. Use floating point numbers for these. Calculate the:

Trimmed Mean
Max, Min
Standard Deviation

Draw a barchart to represent the scores. Include the following in your documentation:

Commented Code

Pls someone help if you can.

We are certainly willing and able to help, but we'd need to know what sort of help you need. What have you done so far, and where are you stuck? Do you know the basics of how to write a function, how to use Python arithmetic, and so forth? Do you know how to calculate the mean, median. etc. by hand, and how you would apply that to writing the program?

Also, what version of Python are you using (2.x or 3.x), and is there a specific environment or IDE you are using for developing the programs?

I will caution you, though: do not expect anyone here to write the programs for you. We will assist you, but we are not a free homework-solving site. Show us that you've made an effort, and we will do what we can to aid you, but we will not and cannot do your work for you.

commented: indeed +14

Hello this is all i have so far,

My problem now is the Trimmed Mean, Max, Min,

also i want to be sure am on the right path so will appreciate any sort of help or support.


Python 2.7


scores = {1,3,4,6,9,19,}
sqrs = []

for score in scores:
    x = score**2

print sqrs 

# Standard Deviation
import math
q = [1,3,4,6,9,19]
avg = float(sum(q))/len(q)
dev = []
for x in q:
    dev.append(x - avg)
sqr = []
for x in dev:
    sqr.append(x * x)
mean = sum(sqr)/len(sqr)
standard_dev = math.sqrt(sum(sqr)/(len(sqr)-1))
print("the standard deviation of set %s is %f" % (q, standard_dev) ) 


OK, you are mostly on the right track, I would say. However, there are things that can be done to improve it. Has your professor covered defining functions yet? If so, I would certainly recommend writing the average as a a function, that way you don't have to repeat the same code in the SD section twice. In fact, I would write all of these as functions, and simply have the main program call them as needed.

Also, while it is useful to have a defined value for the input when testing, don't forget that the actual project assignment calls for getting the input from the user. You should be able to write that as a function, too.

hello agaian, thanks for the reply,i havent done funtions as i missed few class due to the fact that i lost my grand dad,

my college coure teacher barely repeat a class so was told to do a research but at the moment am stuck, been on internet all day but its very hard to find python 2.7 codes on youtube. most are in c++.

pls if anyone can help, i will appreciate, like i said b4 its my 2months studying programming.

Ah, I see. Well, I can help you out I think. Fortunatel,y functions in Python are dead easy, and once you get the idea of them, you'll probably use them quite a bit.

Using a function is already familiar to you; you used the standard functions len(), print(), and sqrt() already. While len() and print() are part of the Python language itself, sqrt() is actually a part of the math library, and not a part of the core language at all. While the libraries are part of what comes with the language, they are separate from the language itself, which is why you need to use import in order to use them.

Writing your own function is almost as easy, but I should explain a little about why you would want to first. There are three main reasons for writing functions in Python (and most programming languages in general). First, they let you give a name to a particular piece of code. This allows you to ''abstract'' the idea of that piece of code, so you don't have to think about what's inside of it; you can just use the name. Second, it makes it easy to use the same piece of code in more than one place, making the program smaller and reducing the number of places you need to fix if you have to change something. Finally, a function can be ''parameterized'', that is to say, it can let you describe ''part'' of a piece of code, without all the values in place, and you can give it the values you want it to work on as ''function arguments''. Similarly, you can have the function return a value, which is sort of the reverse processof passing parameters.

The declaration syntax for a function is just this: the keyword def followed the name of the function, followed by the ''parameter list''. which is just a tuple (sort of like a list, but with parentheses instead of brackets) with zero or more variable names in it. The line ends in a colon, just like if: or while:, and the body of the function is indented the same way those statement's bodies are. A simple function might look like this:

def print_star():

You would then call it like this:


and it would print out one asterisk. Now, this is a really simple function, and not very useful; a slightly more elaborate function might be:

def print_stars(x):
    for n in range(0, x):

Notice how I used the first function inside the second one. If you call print_stars() with an argument of, say, 5:


it would print out five asterisks.

Now let's try computing a value which the function can return:

def square(x):
    return x * x

Calling this with the value of 5 will return 25.

a = square(5)
print(a)          # prints out '25'
print(square(3))  # prints out '9'

You can even have a function call itself, a process called ''recursion'', though you need to make sure you have an if: to check for the ''end condition'' of the recursive call:

def factorial(n):
    if n == 0 or n == 1:
        return 1
        return n * factorial(n - 1)

By now, you should be able to see how to re-write your averaging code as a function and use it in your program.

If your scores don't exceed the line width, then you can use this simple barchart ...

def h_bar(mylist):
    ''' a simple horizontal bar chart '''
    for item in mylist:
        print('-' * item)

scores = [2, 4, 7, 11, 25, 45, 33, 24]


''' result ...
score1 = 1
list1 = []
list2 = []
list3 = []
    score1 = int(raw_input("(Enter 999 to Exit) Enter Score: "))
l = len(list1)
    pos = l/2
    x = float(list1[pos])
    y = float(list1[pos-1])
    median = (x+y)/2
    median = list1[l/2]
trimmedMean = sum(list1) - max(list1) - min(list1)
total1 = (sum(list1))
average = total1/len(list1)
for i in list1:
    x = i - average
for score11 in list2:
    x = score11**2
import math
y = float(sum(list3) / len(list3))
std = math.sqrt(y)
print "Total: ", total1
print "Trimmed Mean: ", trimmedMean
print "Median:", median
print "Average: ", average
print "Standard Deviation: ", std
for score1 in list1:
    for i in range(0,score1):
        print "*", 

I was able to come up with this,but after i enter my numbers, my program wont display my result when i run it.

I am submitting it today so pls, can someone write me what exactly to add to it..its urgent, just help me complete it Please Please Please

Add a print statement to start a new line

for score1 in list1:
    for i in range(0,score1):
        print "*",
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.