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
Which one is the correct answer
STatiana [176]

the right anwser is d


3 0
3 years ago
Lots of Ways to Use Math.random() in JavaScript
Alja [10]

Math.random() is a built-in function in JavaScript that generates a random number between 0 and 1.

<h3>What is Math.random()?</h3>

Math.random() is a useful and versatile function that can add a element of randomness to your JavaScript programs.

This function can be used in a variety of ways in JavaScript programs, such as:

  1. Generating random numbers for games or simulations.
  2. Creating random samples for statistical analysis.
  3. Shuffling elements in an array for a random order.
  4. Selecting random items from a list for a quiz or survey.
  5. Creating unique IDs or keys for objects in a database.

To Know More About built-in function, Check Out

brainly.com/question/29796505

#SPJ4

8 0
1 year ago
Does anyone know what this logo is??
scoray [572]

Answer:

I have got no idea it looks like an older style

8 0
2 years ago
Read 2 more answers
A _____ miniature battery operated transmitter that can be propelled through a non-metallic pipe or purpose of locating
Anna11 [10]
I think it is the model ET-2. Not quite sure.
7 0
3 years ago
What is imagined risk
lara31 [8.8K]
Hello there!

Imagined Risks are simply 'imaginary' risks that are created out of doubt/fear.

Hope This Helps You!
Good Luck :)
3 0
3 years ago
Other questions:
  • Which of the following criteria would not make a person eligible to receive medicare benefits?Which of the following criteria wo
    12·2 answers
  • A web __________, such as internet explorer or mozillaâs firefox, allow users to access the world wide web.
    10·1 answer
  • When powering off your computer is best down using?
    8·2 answers
  • Select the correct answer. Linda has written a program that works well on various operating systems, but she needs to increase t
    10·1 answer
  • Motivation is best defined as
    9·2 answers
  • Why is it important to study in a quiet well lit area
    5·2 answers
  • Create a datafile called superheroes.dat using any text-based editor, and enter at least three records storing superheroes’ name
    9·1 answer
  • A(n) __________ is a server with the original copy of the data that others need.
    12·1 answer
  • For enterprise servers, or servers accessed around the clock, SATA disks are preferred over SAS disks. True or False
    12·1 answer
  • Which of the following rules need to be followed when using variables?<br> Choose all that apply.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!