subject

Reset to Starter Code

Write 3 functions in the starter code below such that:

add_to_dict(): takes a dictionary, a key, a value and adds the key, value pair to the dictionary. If key is already in dictionary then it displays the error message: "Error. Key already exists.". Returns dictionary.

remove_from_dict(): takes a dictionary and key and removes the key from the dictionary. Returns dictionary. If no such key is found in the dictionary then it prints: "No such key exists in the dictionary.". Hint: Use try-except.

find_key(dictt, key): takes dictionary and key and prints value corresponding to the key from the dictionary: print("Value: ", value). If key is not found, then prints: "Key not found." Hint: Use try-except

Example:

Menu:

add(a), remove(r), find(f): a

Key: rich

Value: 1

More (y/n)? y
Menu:

add(a), remove(r), find(f): a

Key: alireza

Value: 2

More (y/n)? n
[('alireza', '2'), ('rich', '1')]

Example 2:

Menu:

add(a), remove(r), find(f): a

Key: pranshu

Value: 1

More (y/n)? y
Menu:

add(a), remove(r), find(f): r

key to remove: enbody
No such key exists in the dictionary.

More (y/n)? n

code

#add_to_dict() goes here:

#remove_from_dict() goes here

#find_key() goes here

def main():
more = True
dictt = {}
dictlst = []
while more:
print("Menu: ")
choice = input("add(a), remove(r), find(f): ")
if choice. lower() == "a":
key = input("Key: ")
value = input("Value: ")
dictt = add_to_dict(dictt, key, value)
elif choice. lower() == "r":
key = input("key to remove: ")
dictt = remove_from_dict(dictt, key)
elif choice. lower() == "f":
key = input("Key to locate: ")
find_key(dictt, key)
else:
print("Invalid choice.")

do_more = input("More (y/n)? ")
if do_more. lower() != 'y':
more = False
if dictt:
for key, value in dictt. items():
temp = (key, value)
dictlst. append(temp)
print(sorted(dictlst))
main()

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:00
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print
Answers: 3
question
Computers and Technology, 23.06.2019 01:30
How do you set up a slide show to play continuously, advancing through all the slides without requiring your interaction? a. click set up slide show, and then select the loop continuously until ‘esc' and show without narration options. b. click set up slide show, and then select the loop continuously until ‘esc' and use timings, if present options. c. click set up slide show, and then select the show presenter view and use timings, if present options. d. click set up slide show, and then select the show without animation and browsed at a kiosk (full screen) options.
Answers: 3
question
Computers and Technology, 23.06.2019 01:30
1. which of the following is a search engine? a) mozilla firefox b)internet explorer c)google d)safari 2. which of the following statements is true? a) all search engines will provide the same results when you enter the same query. b) all search engines use the same amount of advertisements. c) some search engines are also browsers. d) search engines often provide different results, even when you enter the same query.
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
[java] create an application called registrar that has the following classes: a. a student class that minimally stores the following data fields for a student: - name - student id number - number of credits - total grade points earned and this class should also be provides the following methods: - a constructor that initializes the name and id fields - a method that returns the student name field - a method that returns the student id field - methods to set and retrieve the total number of credits - methods to set and retrieve the total number of grade points earned. - a method that returns the gpa (grade points divided by credits) b. an instructor class that minimally stores the following data fields for an instructor: - name - faculty id number - department the following methods should be provided: - a constructor that initializes the name and id fields - methods to set and retrieve the instructor’s department. c. a course class that minimally stores the following data for a course: - name of the course- course registration code- maximum number of 35 students- instructor- number of students- students registered in the course (an array)the following methods should also be provided: - a constructor that initializes the name, registration code, and maximum number of students- methods to set and retrieve the instructor- a method to search for a student in the course; the search should be based on an id number.- a method to add a student to the course. if the course is hill, then an exception with an appropriate message should be raised (try creating your own exception class for this). also, be sure that the student is not already registered in the course. the list of students should be in the order that they registered.- a method to remove a student from the course. if the student is not found, then an exception with an appropriate message should be raised (use the same exception class mentioned a method that will allow course objects to be output to a file using object serialization- a method that will allow course objects to be read in from a file created with object serializationyou will note that the student and instructor classes described above have some commonality. create aperson class that captures this commonality and uses it as a base class for student and instructor. this class should be responsible for the name and id fields and also provide atostring method that returns a string of the form name, id. this will be the inheritedtostring method for the student and instructor classes.1. draw a uml diagram for diss application.2. implement the previous classes in java. write a main program that can serve as a test class that tests all of the methods created and demonstrates that they are working
Answers: 2
You know the right answer?
Reset to Starter Code

Write 3 functions in the starter code below such that:
Questions
question
Mathematics, 20.07.2021 21:10
question
Mathematics, 20.07.2021 21:10
question
English, 20.07.2021 21:10
question
Mathematics, 20.07.2021 21:10
Questions on the website: 13722363