Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9, Problem 3AW
Assume the variable dct references a dictionary. Write an if statement that determines whether the key 'James' exists in the dictionary. If so, display the value that is associated with that key. If the key is not in the dictionary, display a message indicating so.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Hjj-+(
Python
Assume that the variable data refers to the dictionary {'b':20, 'a':35}. Write the expressions that perform the following tasks:
a. Replace the value at the key 'b' in data with that value's negation. b. Add the key/value pair 'c':40 to data.c. Remove the value at key 'b' in data, safely. d. Print the keys in data in alphabetical order.
Chapter 9 Solutions
Starting Out with Python (4th Edition)
Ch. 9.1 - An element in a dictionary has two parts. What are...Ch. 9.1 - Which part of a dictionary element must be...Ch. 9.1 - Suppose ' start' : 1472 is an element in a...Ch. 9.1 - Suppose a dictionary named employee has been...Ch. 9.1 - What will the following code display? stuff = {1 :...Ch. 9.1 - Prob. 6CPCh. 9.1 - Suppose a dictionary named inventory exists. What...Ch. 9.1 - What will the following code display? stuff = {1 :...Ch. 9.1 - What will the following code display? stuff = {1 :...Ch. 9.1 - What is the difference between the dictionary...
Ch. 9.1 - Prob. 11CPCh. 9.1 - Prob. 12CPCh. 9.1 - What does the values method return?Ch. 9.2 - Prob. 14CPCh. 9.2 - Prob. 15CPCh. 9.2 - Prob. 16CPCh. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - Prob. 22CPCh. 9.2 - After the following statement executes, what...Ch. 9.2 - After the following statement executes, what...Ch. 9.2 - Prob. 25CPCh. 9.2 - Prob. 26CPCh. 9.2 - After the following code executes, what elements...Ch. 9.2 - Prob. 28CPCh. 9.2 - After the following code executes, what elements...Ch. 9.2 - After the following code executes, what elements...Ch. 9.2 - After the following code executes, what elements...Ch. 9.2 - Prob. 32CPCh. 9.3 - Prob. 33CPCh. 9.3 - When you open a file for the purpose of saving a...Ch. 9.3 - When you open a file for the purpose of retrieving...Ch. 9.3 - Prob. 36CPCh. 9.3 - Prob. 37CPCh. 9.3 - Prob. 38CPCh. 9 - You can use the __________ operator to determine...Ch. 9 - You use ________ to delete an element from a...Ch. 9 - The ________ function returns the number of...Ch. 9 - You can use_________ to create an empty...Ch. 9 - The _______ method returns a randomly selected...Ch. 9 - The __________ method returns the value associated...Ch. 9 - The __________ dictionary method returns the value...Ch. 9 - The ________ method returns all of a dictionary's...Ch. 9 - The following function returns the number of...Ch. 9 - Prob. 10MCCh. 9 - Prob. 11MCCh. 9 - This set method removes an element, but does not...Ch. 9 - Prob. 13MCCh. 9 - Prob. 14MCCh. 9 - This operator can be used to find the difference...Ch. 9 - Prob. 16MCCh. 9 - Prob. 17MCCh. 9 - The keys in a dictionary must be mutable objects.Ch. 9 - Dictionaries are not sequences.Ch. 9 - Prob. 3TFCh. 9 - Prob. 4TFCh. 9 - The dictionary method popitem does not raise an...Ch. 9 - The following statement creates an empty...Ch. 9 - Prob. 7TFCh. 9 - Prob. 8TFCh. 9 - Prob. 9TFCh. 9 - Prob. 10TFCh. 9 - What will the following code display? dct =...Ch. 9 - What will the following code display? dct =...Ch. 9 - What will the following code display? dct =...Ch. 9 - What will the following code display? stuff =...Ch. 9 - How do you delete an element from a dictionary?Ch. 9 - How do you determine the number of elements that...Ch. 9 - Prob. 7SACh. 9 - What values will the following code display? (Dont...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - After the following statement executes, what...Ch. 9 - What will the following code display? myset =...Ch. 9 - After the following code executes, what elements...Ch. 9 - Prob. 16SACh. 9 - Prob. 17SACh. 9 - Prob. 18SACh. 9 - After the following code executes, what elements...Ch. 9 - Prob. 20SACh. 9 - Write a statement that creates a dictionary...Ch. 9 - Write a statement that creates an empty...Ch. 9 - Assume the variable dct references a dictionary....Ch. 9 - Assume the variable dct references a dictionary....Ch. 9 - Prob. 5AWCh. 9 - Prob. 6AWCh. 9 - Prob. 7AWCh. 9 - Prob. 8AWCh. 9 - Prob. 9AWCh. 9 - Prob. 10AWCh. 9 - Assume the variable dct references a dictionary....Ch. 9 - Write code that retrieves and unpickles the...Ch. 9 - Course information Write a program that creates a...Ch. 9 - Capital Quiz The Capital Quiz Problem Write a...Ch. 9 - File Encryption and Decryption Write a program...Ch. 9 - Unique Words Write a program that opens a...Ch. 9 - Prob. 5PECh. 9 - File Analysis Write a program that reads the...Ch. 9 - World Series Winners In this chapters source code...Ch. 9 - Name and Email Addresses Write a program that...Ch. 9 - Blackjack Simulation Previously in this chapter...Ch. 9 - Word Index Write a program that reads the contents...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- keys = ['name', 'last', 'job_title', 'email']Faculty2 = Faculty = dict.fromkeys(keys)print(Faculty2) Use the dictionaries that you created for faculty members. Be sure that all the dictionaries have the same keys: name, last name, etc. If there are keys or values missing, add them. If you do not have the value, you can use 'n/a' or 'TBD'. Make a list of the dictionaries. Loop the list to print all the information available to each faculty member. In Python lang please.arrow_forwardPython Programming Assignment: Create a dictionary that takes a basketball team's information (that includes team's name and points) as parameter, creates a teams_dict and returns it. Also, create a parameter for write_file parameter that opens current results text file in write mode and writes the dictionary information to file as per format and closes the file.arrow_forwardOverview This program will have you use a loop to prompt a user for three foods and their country of origin and then store them in a dictionary called food_dict). Then, it will prompt the user for a dish that they like and then will tell them the country of origin. Expected Output Example 1 What is good to eat? Tacos What country is that from? Mexico What is good to eat? Pho What country is that from? Vietnam What is good to eat? Burgers What country is that from? America What dish do you like? Burgers Burgers is from America Example 2 What is good to eat? Pizza What country is that from? Italy What is good to eat? Spaghetti What country is that from? Italy What is good to eat? Gelato What country is that from? Italy What dish do you like? Pizza Pizza is from Italy Specifications • You should submit a single file called M4A2.py • It should follow the submission standards outlined here: Submission Standards • Your program should start by defining an empty dictionary called food_dict •…arrow_forward
- Given variable cities = {'GA' : 'Atlanta', 'NY' : 'Albany', 'CA' : 'San Diego'} write statement to delete then add an element to cities, so value of citiesbecomes {'CA': 'San Diego', 'NY': 'Albany', 'IN': 'Indiana'} Note: the order of the display of entries in a dictionary are not in a specific order.)arrow_forwardimport are as are# A dictionary for the simplified dragon text game# The dictionary links a room to other rooms.rooms = {'Great Hall': {'South': 'Bedroom'},'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},'Cellar': {'West': 'Bedroom'}}location = 'Great Hall' # set starting room# Based on the start room (a key), what is the corresponding dictionary value?print("\n", rooms[location])# Available directionsprint(rooms[location].keys())print(*rooms[location].keys())# Available roomsprint(rooms[location].values())print(*rooms[location].values())direction = ['South', 'North', 'East', 'West']# game loopwhile direction != "exit":print('\nYou are in the',location)possible_moves = rooms[location].keys()print('possible moves', *possible_moves)direction = input("Which direction should I go?").strip().lower()print('You chose to go:', direction)I am supposed to make a program to be able to move from room to room in python, and exit, how do I finish this is as far as I have completedarrow_forwardPerform the following tasks: Create a dictionary named color_dict containing key-value pairs 'red': 222, 'green': 184, and 'blue': 135. Read strings key_read and value_read from input. Add key_read and value_read as a new key-value pair to color_dict with key_read as the key and value_read as the value.arrow_forward
- Assume that d refers to a dictionary. Write a statement in Python that retrieves from the dictionary the value that is associated with the key 'answer', and assigns this value to the result variable.arrow_forwardQ1) Create a dictionary with the following key-value pairs, 'name' with 30 names 'age' with 30 values (generate 30 random integers from 18 to 70) 'height' with 30 values (generate 30 random integers from 150 to 200) 'weight' with 30 values (generate 30 random integers from 50 to 100) 'experience' with 30 values (generate 30 random integers from 2 to 8) (hint: you must use numpy library to generate the numbers) make a dataframe from a dictionary named df. write down a statement to get columns 'name', 'weight' and 'experience' write down statements to find the maximum, the minimum, the average, the median and the variance of column 'height'. ● ● ● ● ● ● ● write down a statement to sort the values of column 'experience and make the change permanent. write down statement to get the rows where the value of weight is greater than 77 and the value of height is a multiple of 5. Q2) Solve the system of linear equations using Python (use sympy library) 7x - 13y = 51 6x 19y 244arrow_forwardScenario 1 a. Create a dictionary with the following items: {"a":120, "b": 1200, "c": 80, "d": 70, "e": 50, "f": 40, "g": 120, "h": 50, "i": 90, "j": 85} b. Display in a tabular format all the keys only c. Display all the values divided by 10. d. Count all values that are more than 100. e. Display all keys which values are 50. g. Display in a tabular format all the valuesarrow_forward
- Python program named "YourMuseumID_Exhibits.py" focusing on museum exhibit data: You have a list of dictionaries representing exhibits in a museum. Each dictionary contains the exhibit name, the number of artifacts on display, and the historical era it covers. Perform the following tasks: (a) Calculate and display the total number of artifacts on display for all exhibits in the museum. (b) Identify and display the exhibit with the highest number of artifacts on display. (c) Implement a function that takes a user-input exhibit name and searches for it in the list. If found, display the number of artifacts on display and the historical era it covers; if not found, print a message indicating that the exhibit is not in the museum. (d) Implement a sorting algorithm of your choice to sort the exhibits based on the number of artifacts on display in descending order and display the sorted list. Make sure to incorporate functions for each task and display the results in the main function with…arrow_forwardindividual characters using their 0-based index. Hint: You will need to do this for checking all the rules. However, when you access a character .arrow_forwardAssuming food is a Dictionary, what does the following statement do? food[101] = "Cheesburger"; Question 63 options: a) After the statement executes, the Dictionary will have an element with the key 101 and the value “Cheeseburger.” b) After the statement executes, the Dictionary will have an element with the key “Cheeseburger” and the value 101 c) After the statement executes, the element at position 101 will have the key “Cheeseburger.” d) After the statement executes, the Dictionary will have 101 elements, each with the key “Cheeseburger.”arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Dictionaries - Introduction to Data Structures (Episode 8); Author: NullPointer Exception;https://www.youtube.com/watch?v=j0cPnbtp1_w;License: Standard YouTube License, CC-BY