Question

In: Computer Science

I am working on making a simple gradebook. How it works is it asks user for...

I am working on making a simple gradebook. How it works is it asks user for name and grade. It does this for multiple instances until the person types quit to end the program. The code I have here works. My question is how do I print the output in alphabetical order?

Output from the input I put into my program:

David 98

Annabelle 87

Josh 91

Ben 95

What I want my code to do (in alphabetical order):

Annabelle87

Ben 95

David 98

Josh 91

Here is my code for the program:

grades = {}


def set_grade(name, grade):
grades[name] = grade


def print_grades_names():
for i in grades.keys():
print('{} {}'.format(i, str(grades[i])))

while True:
name = input("Enter a name (or 'quit' to stop): ")
if name == 'quit':
break
grade = input("Enter a grade: ")
set_grade(name, grade)


(print_grades_names())

Solutions

Expert Solution

Please look at my code and in case of indentation issues check the screenshots.

---------------main.py-------------------------

grades = {}


def set_grade(name, grade):
   grades[name] = grade


def print_grades_names():
   for i in sorted(grades.keys()):                       #use sorted, to sort the keys(names)
       print('{} {}'.format(i, str(grades[i])))       #print name and grade


while True:
   name = input("Enter a name (or 'quit' to stop): ")
   if name == 'quit':
       break
   grade = input("Enter a grade: ")
   set_grade(name, grade)


print_grades_names()

--------------Screenshots-----------------------

------------------Output----------------------

-----------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.


Related Solutions

I am working on making a simple grade book that will take user input like name...
I am working on making a simple grade book that will take user input like name and grade and then return the name and grade of multiple inputs when the person quits the program. Here is the code that I have been working on. This is in Python 3. I can get one line to work but it gives me an error. Here is what it is supposed to look like: These are just examples billy 100 greg 60 jane...
I am working on these study questions and am having trouble understanding how it all works...
I am working on these study questions and am having trouble understanding how it all works together. Any help would be greatly appreciated!! An all equity firm is expected to generate perpetual EBIT of $50 million per year forever. The corporate tax rate is 0% in a fantasy no tax world. The firm has an unlevered (asset or EV) Beta of 1.0. The risk-free rate is 5% and the market risk premium is 6%. The number of outstanding shares is...
How do digital signals work? I am trying to explain how a simple coil speaker works,...
How do digital signals work? I am trying to explain how a simple coil speaker works, I understand that a current creates an electromagnet in the coil whose magnetic field interacts with that that of the permanent magnet... however I am confused as to how the electricity is sent from the phone and into the coil, can someone explain this please? Does this relate to motion of waves? are they electromagnetic waves being converted in to vibrational waves? im confused!!!
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
I am working on a C++ program, where a user puts in a notation a playing...
I am working on a C++ program, where a user puts in a notation a playing card and the output is the full name of the card.(ex: KH = King of Hearts) I have most of it working but I want to have an error come up when the user puts in the wrong info and then loop back to the original question. Am I setting it up wrong? Pasted below is my code #include<iostream> #include<string> using namespace std; int...
I am making a working reagent that requires a 50:1 ratio (50 of reagent A and...
I am making a working reagent that requires a 50:1 ratio (50 of reagent A and 1 of reagent B) and a total volume of 600uL. Therefore, I need 588uL of reagent A (water) and 12uL of reagent B (lead acetate). I need to make a solution of lead acetate (reagentB) with: 3mM,7.7mM, and 46mM. Upon calculating the mass needed to make 3mM, 7.7mM, and 46mM I got: 0.9756 mg, 2.504 mg, and 14.9592 mg respectively and to each mass...
I need assistance in making a simple html and php script that lets a user explor...
I need assistance in making a simple html and php script that lets a user explor the RGB color specturum. It should be able to use 6 buttons (R+,G+,B+,R-,G-,B-) that when pressed, add or subtract 2 points (ranging from 0-255) of that color from the RGB ratio. The new RGB color is then displayed in a small window/box at the bottom of the page for the user to see. This should allow the user to explore all the different colors...
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
I am so lost on this. I am making a B in this class but I...
I am so lost on this. I am making a B in this class but I can not seem to get this project completed. Please help. ACC-120 Project – Financial Accounting This assignment supports the following outcomes: ·          Prepare journal and ledger entries for a service or merchandising business. ·          Prepare year-end statements for a service or merchandising business. ·          Report cost decisions using accounting principles and financial statement analysis. ·          Evaluate how knowledge, skills, and attitudes learned in this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT