I recently started learning Python and am busy going through the Codecademy tutorial for it. I just completed the tutorial where you create a program that determines averages of marks from dictionaries. Heres the current code:
lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
class_list = [lloyd, alice, tyler]
def average(numbers):
total = sum(numbers)
total = float(total)
total = total / len(numbers)
return total
def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return homework * 0.1 + quizzes * 0.3 + tests * 0.6
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
return average(results)
print get_class_average(class_list
But what I want to do as an extension is make it more user friendly by making the program ask the user to input lloyd
in the first line as well as input all the values in the dictionary. Furthermore I'd like to make it so that the program generates a new dictionary every time the user inputs the name of the dictionary for example the lloyd
on the first line. Then fill in class_list
with all of the dictionaries. Lastly I want to make it so the user can also input the weightings of the marks in the line:
return homework * 0.1 + quizzes * 0.3 + tests * 0.6
I'm having trouble doing this so any help would be much appreciated.