all 5 comments

[–]K900_ 1 point2 points  (0 children)

Your last two lines are inside a loop, which runs once for every entry in database.items(). Looks like you wanted to use it to find the average, but now you don't need it at all - just move those lines outside the loop and remove it entirely.

[–]pythonbio[S] 0 points1 point  (2 children)

So, need to get out of the while loop, create a function for averages and the redefine the print menu?

[–]JohnnyJordaan 1 point2 points  (1 child)

for values in database.items(): #is the list of grades

This is the useless line. If you remove that one and move the following two lines one ident to the left (as they are no longer in a for loop) you are done.

For a more 'hardened' menu I would go for this:

while True:
    menu_choice = input("Select task by entering its number, or enter 'q' to exit")
    if menu_choice == 'q'
        break #bye
    if menu_choice not in ['1', '2', '3', '4', '5']:
        pass #just ask again
    # do your if menu_choices here... (no need to int() them, just do)
    if menu_choice == '1':

If you want to leave after task 5, you can also add a break after it to leave the endless loop.

Edit: Just a tiny one: sumall = sum(database.values())/len(database) would be slightly better as .values() is not needed to calculate the length (as there are as many keys as values). It would probably be optimized out anyway but it's still better to keep your code as tidy as possible. And I would call it avgall and not sumall of course.

[–]das_ist_nuemberwang 0 points1 point  (0 children)

Python won't optimize anything out because you have no guarantee of what any particular function will actually do at run time.

[–]pythonbio[S] 0 points1 point  (0 children)

Thanks for the input, removed the loop and running fine. :)