# Wanted to check if the gradebook code is correct

here is the code:

``````
Bob = {"name": "bob", "assigbment": [48, 39, 98, 87],
"presentation": [78, 78, 89, 78], "lab_task": [67, 89, 89, 90]}
Jay = {"name": "bob", "assigbment": [48, 39, 98, 87],
"presentation": [78, 78, 89, 78], "lab_task": [67, 89, 89, 90]}
# print out info
print(Bob, Jay)

def average(marks):
total_sum = sum(marks)
total_sum = float(total_sum)

def get_average(student):
ass_avg = average(student["Assignment"])
pre_avg = average(student["presentation"])
weight = ass_avg * 0.6 + pre_avg * 0.1 + lab_avg * 0.3
return weight

if weight >= 90:
return ("HD")
elif weight >= 80:
return ("D")
elif weight >= 70:
return ("CR")
elif weight >= 60:
return "P"
else:
return ("f")

students = [Bob, Jay]
results = []

def class_average(students):
results.append(get_average(students[0]))
results.append(get_average(students[1]))
class_avg = average(results)
return class_avg

``````

Do you have a question? Is your program doing what you expect it to?

A good way to check that the parts work correctly is to write tests: unittest â€” Unit testing framework â€” Python 3.11.0 documentation.

1 Like

When you say â€ścorrectâ€ť, correct in what way?

Right now, none of the functions are being used (all of which should be placed ahead of any of the main code). Also, the way this seems to be panning out, youâ€™ll need to edit the code in order to add more students. Would it not be better to have an app that was not so high maintenance?

Also, simply printing the dictionaries is not so pretty, so the data presentation could use some work.

Iâ€™ve not checked any of the math.

My comments are meant as constructive criticism, not a knock down, so I trust that theyâ€™ll be taken in the intended way.

b.t.w: Jay and Bob are the same; a simple C&P error?

alright thank you ill work on it

I think (and please correct me if Iâ€™m wrong) the reason that youâ€™re adopting an â€śedit the codeâ€ť approach for saving data, is that youâ€™re unsure of how else to save the data?

If thatâ€™s the case, then you could use a technique that Iâ€™ve used to solve the same issue: shelve â€” Python object persistence â€” Python 3.11.0 documentation

Itâ€™s a very light weight solution with which to simply save the current sate of an object (or objects) such as a dictionary, which can be restored as and when the app is once again run.

Is this the kind of base app that you have in mind?

``````def new_grades(entry):
print(f"Enter grades for {entry} (an empty entry to finish)")
else:
break

quit = False
while not quit:
name = input("Name (quit to exit): ")
if name == 'quit':
break
else:
if name in names:
else:
}

# this is to simply show that the dictionary has indeed been updated
print("\nexit\n")
# the grade book could be saved using the technique that I've suggested
``````

Itâ€™s far from a complete solution, with no error checking, but more a simple proof of concept.

If this is along the lines that you have in mind and need help to further develop, then thatâ€™s fine. If not, well, thatâ€™s fine also, but at the very least I hope that it serves as some sort of a guide (maybe).

1 Like

thanks for the help im new to all this doing school for this part time, trying to do it in my spare time after my full time work in a different career thats why its a little bit hard for me unfortunately

It not easy for anyone, at the start, but over time, youâ€™ll learn more and it becomes easier to see solutions, based on the knowledge and experience you gain. The only way to learn Python, is to use Python.

I didnâ€™t intend to discourage you and I hope Iâ€™ve not done so.

The code that you posted is 99% unused. This is the only part that does anything, as is:

``````Bob = {"name": "bob", "assignment": [48, 39, 98, 87],
"presentation": [78, 78, 89, 78], "lab_task": [67, 89, 89, 90]}
Jay = {"name": "bob", "assignment": [48, 39, 98, 87],
"presentation": [78, 78, 89, 78], "lab_task": [67, 89, 89, 90]}
# print out info
print(Bob, Jay)
``````

If what Iâ€™ve posted is what you have in mind and you want to incorporate the functions that you have written, then I see no reason that it canâ€™t be done.

That said, Iâ€™ve not gone deep into this, as I was unsure on how you wanted to proceed.

nah im not discouraged and i appreciate the help

1 Like

Good to know.

You clearly have some experience on which to build, so Iâ€™m sure that you can do this. If you need help (which we all need, from time to time), just ask.

Try to post code that, for the better part, is working, then say what itâ€™s not doing, but you want it to do. That way itâ€™s more progressive.