Question

in python

Write a program that keeps a dictionary in which both keys and values are strings—names of students and their course grades.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

dict = {}
inp=raw_input("Select option \n 1 for adding. \n 2 for removing. \n 3 for modifying. \n 4 for printing. \n 5 for exit. \n")
while (inp != '5'):
   if inp =='1' :
       name=raw_input("Enter the name of student: ")
       grade=raw_input("Enter its grade: ")
       dict[name]=grade
   elif inp =='2' :
       name=raw_input("Enter the name: ")
       try:
           dict.pop(name)
       except :
           print("Not found. ")
   elif inp =='3' :
       name=raw_input("Enter the name of student: ")
       grade=raw_input("Enter grade: ")
       dict[name]=grade
   elif inp =='4' :
       for x in sorted(dict):
           txt="{} : {} "
           print(txt.format(x,dict[x]))
   else :
       print("You have entered wrong number")
   inp=raw_input("Select option \n 1 for adding. \n 2 for removing. \n 3 for modifying. \n 4 for printing. \n 5 for exit. \n")

Add a comment
Know the answer?
Add Answer to:
in python Write a program that keeps a dictionary in which both keys and values are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that keeps a map in which both keys and values are strings—the names...

    Write a program that keeps a map in which both keys and values are strings—the names of students and their course grades. Prompt the user of the program to add or remove students, to modify grades, or to print all grades. The printout should be sorted by name and formatted like this: Carl: B+ Joe: C Sarah: A

  • Your program has a dictionary called classes. The keys in classes are teacher's last names (as...

    Your program has a dictionary called classes. The keys in classes are teacher's last names (as strings), and the corresponding values are the number of students in that teacher's class. For example, if Mr. Brown has 17 students in her class, then 'Brown' might be a key in classes with a corresponding value of 17. Write a few lines in Python that will do the following: Ask the user to enter the last name of a teacher IF that last...

  • Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys()...

    Storing data and adding to data in a dictionary: Experiment with Python dictionaries and their keys() member function that returns a list of a dictionary's keys. You can check if a particular key is in a dictionary by using the in test with the keys list. For example, if our dictionary is MyDict = { 1: 'One', 2: 'Two', 3: 'Three' } Then ( 2 in MyDict.keys() ) evaluates to True, indicating that 2 is a valid key for MyDict....

  • using python Write a function that takes a dictionary and a list of keys as 2...

    using python Write a function that takes a dictionary and a list of keys as 2 parameters. It removes the entries associated with the keys from the given dictionary Your function should not print or return anything. The given dictionary should be modified after the function is called Note: it means that you can't create another dictionary in your function. Since dictionaries are mutable, you can modify them directly def remove_keys (dict, key_list) "" "Remove the key, value pair from...

  • Write a "PYTHON" program to prompt the user to enter a fist name, last name, student...

    Write a "PYTHON" program to prompt the user to enter a fist name, last name, student ID and GPA. Create a dictionary with the data. Print out the data. Then remove the GPA and print again.

  • Write a Python program that keeps reading in names from the user, until the user enters...

    Write a Python program that keeps reading in names from the user, until the user enters 0. Once the user enters 0, you should print out all the information that was entered by the user. Use this case to test your program: Input: John Marcel Daisy Samantha Nelson Deborah 0 ================ Output: John Marcel Daisy 25 Samantha Nelson Deborah Hints: Create an array Names to hold the input names. Use the Names.append(x) function to add a new name to the...

  • Simple Python Program Working with strings Write a Python program to read in a number of...

    Simple Python Program Working with strings Write a Python program to read in a number of strings from the user. Stop when the user enters “Done”. Then check if each of the strings contains all the letters of the alphabet. Print the results in the form of a dictionary, where they keys are the strings and the values are the Truth Value for the string, which you just calculated. Sample Run: Enter the strings: taco cat The quick brown fox...

  • Write a program that asks the user for a student name and asks for grades until...

    Write a program that asks the user for a student name and asks for grades until the user enters a non-number input, it should then ask if the user wants to enter another student, and keep doing the process until the user stops adding students. The student’s must be stored in a dictionary with their names as the keys and grades in a list. The program should then iterate over the dictionary elements producing the min, max, and mean of...

  • Please help with this exercise on Python program involving the use of dictionary. ### This exercise...

    Please help with this exercise on Python program involving the use of dictionary. ### This exercise involves building a non-trivial dictionary. ### The subject is books. ### The key for each book is its title ### The value associated with that key is a dictionary ### ### In that dictionary there will be Three keys: They are all strings, they are: ### ### "Pages", "Author", "Publisher" ### ### ### "Pages" is associated with one value - an int ### ###...

  • Write a Python program to create userids: You work for a small company that keeps the...

    Write a Python program to create userids: You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000 Your job is to create a program assign usernames for a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT