1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ugo [173]
3 years ago
15

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
Computers and Technology
1 answer:
shepuryov [24]3 years ago
4 0

Answer:

Required code is given below:

Explanation:

def add_to_dict(dictt, key,value):

if key in dictt.keys():

print("Error. Key already exists.")

else:

dictt[key]=value

return dictt

def remove_from_dict(dictt,key):

try:

dictt[key]

dictt.pop(key, None)

return dictt

except KeyError:

print("No such key exists in the dictionary.")

def find_key(dictt,key):

try:

value=dictt[key]

print("Value: ", value)

except KeyError:

print("Key not found.")

You might be interested in
John is directing a television series. He has to shoot a scene that presents the lead character in a dominating and commanding p
user100 [1]
Answer is high angle so it hits better lighting
7 0
2 years ago
Which of the following is a regional accreditation agency?
Sveta_85 [38]

Answer:

A. Middle States Association of Colleges and Schools

Explanation:

The Middle States Association of Colleges and Schools (Middle States Association or MSA) is a non-profit association that performs regional accreditation of schools both public and private  in the Mid-Atlantic region of the United States and for some institutions with an American origin. The MSA has three commissions:

  1. Middle States Commission on Higher Education (MSCHE)
  2. Middle States Commission on Elementary Schools (MSCES)
  3. Middle States Commission on Secondary Schools (MSCSS)
4 0
3 years ago
What should you do to help prepare yourself for the delivery of your presentation? you can chose more then one
Lubov Fominskaja [6]
1 makes sense for somewhere you haven't been before. 2 could be interesting, but it's a bit superfluous if not required. 3 is the most important and essential. Some teachers don't want presenters to look at the board/read their slides word for word when they present, so it might be a good idea to have note cards instead.

Hope this helps!
4 0
3 years ago
Python Write a program that asks the user for an integer and then prints out all its factors.
scoray [572]

Answer:

def display_factors(num):

   for counter in range(1, num+1):

       if num % counter == 0:

           print(counter)

int_num= int(input("Enter a number : "))

print("The factors for {} are : ".format(int_num))

display_factors(int_num)

Explanation:

The function display_factors is used to display all factors of a number entered by a user.

  • In this  for counter in range(1, num+1) the for loop is iterated until counter is greater  to num is false.   Counter variable starts from 1 and ends when it gets greater than the input number.
  • if num % counter == 0: In this statement, each loop  iteration, checks whether a number (num) is exactly divisible by counter. It is the condition for counter to be a factor of num.
  • print(counter) This is used to display factors of an input number
  • int_num= int(input("Enter a number : ")) This statement asks user to enter a number (int_num) which will be an integer.
  • display_factors(int_num) This calls display_factors number to find the factors of an input number.

7 0
4 years ago
what is the most state-of-the-art computer network Hardware in terms of power, integration, and merging?
Vika [28.1K]
Apple is the most state of the art computer
5 0
3 years ago
Other questions:
  • A file that contains program code is called a ____________.
    13·1 answer
  • Using C++, Write a full class definition for a class named Acc1, containing no constructors, functions, or data members (i.e., a
    12·2 answers
  • Which hexadecimal number is equivalent to the decimal number 11?
    13·1 answer
  • Present a detailed data model for your project scenario. You can create your data model using Microsoft Visio 2010, which you wi
    10·1 answer
  • Write a recursive function that returns 1 if an array of size n is in sorted order and 0 otherwise. Note: If array a stores 3, 6
    6·1 answer
  • What should you consider when developing your website content?​
    6·2 answers
  • NEED HELP ASAP
    13·2 answers
  • What 3 types of data can be entered in a spreadsheet
    14·1 answer
  • What was the most surprising thing you learned this term? Why did it surprise you? ​
    9·1 answer
  • A network administrator has asked robin, a network engineer, to use ospf (open shortest path first) along with rip (routing info
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!