Skip to content
Advertisement

Curve grades fx (list operation and loops) python

I’m trying to put together a fx that I has a user input a list of grades and # of points to curve by. The fx should then add the amount to “curve by” to each test score and then return the avg. In one fx I am able to ask for grades, amt to curve by, and make a list with the original grades and add the amt of points to each grade. In the second fx I can sum the new list (w/out sum fx -important) and then then take and return the avg. Is it possible to put these to together in one fx? For this assignment I can use for/while loops and conditionals.

1). Take list and add points to make a new list

grades = [int(x) for x in input("Please enter the grades separated by a space").split()]

c = float(input("Please enter the number of points to curve by: "))

new = [ ]

def addcurve(grades, c):
    for n in grades:
        new.append(n+c)
    return new

print(addcurve(grades, c))

[OUT]: [94.0, 45.0, 78.0, 95.0, 60.0, 74.0]

2). Sum the new list and taking avg

[IN]:
def sumavg(new):
    total_sum = 0
    for n in new:
        total_sum += n  
        gt = len(new)
        final = total_sum/gt
    return "%.2f" %(final)

print(“The new average after curving the grades is”, sumavg(new))

[OUT]: The new average after curving the grades is 74.33

If anyone has an insight please let me know!

Thank you!

Cheers,

Rachel

Advertisement

Answer

First of all, it’s bad practice to declare a variable outside a function, that the function uses to store the result of it’s operation and return it. Instead, declare new = [] inside addcurve()

Secondly, the function you want is:

def foo(grades, c):
    total_sum = 0
    for n in grades:
        total_sum += n+c
    final = total_sum/len(grades)
    return "%.2f" %(final)
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement