Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

University of California San Diego Python Programming Code

University of California San Diego Python Programming Code

University of California San Diego Python Programming Code

Description

Exercise

Dictionaries are one of the fundamental types in Python used to store collections of data. A dictionary uses names which identify the data they hold.

One of the primary reasons for this collection type is that it allows for grouping of related data, much like how data is grouped in the real world. For example, if you wanted to model a person with a dictionary, you could write something like this:

human = {
    "first_name": "Paul",
    "last_name": "Atreides",
    "favorite_food": "spice",
    "age": 35
}

Notice there are identifiers for human attributes such as first name, last name, and age.

You can later retrieve an identifier’s value using “bracket notation”:

human_first_name = human["first_name"]
print("The human's first name is", human_first_name)

You can also create or update an identifier’s value using assignment with “bracket notation”:

human["fear"] = None
print("The human is afraid of", human["fear"]
  1. Create a dictionary using the curly brace syntax ({ ... }) with the three keys ("first_name", "last_name", and "hobby") with appropriate string values, and assign the dictionary to the variable person.
  2. Print the value of the person variable. Run the script and confirm that the printed dictionary displays all three key-value pairs at once.
  3. Using square bracket notation ([ ... ]), get the value stored under the "first_name" key of the dictionary stored in the person variable and assign it to the variable first_name.
  4. Using the get() method, get the value stored under the "last_name" key of the dictionary stored in the person variable and assign it to the variable last_name.
  5. Using the get() method, attempt to get the value stored under the "middle_name" key (which doesn’t exist, but try it anyway) of the dictionary stored in the person variable and assign it to the variable middle_name.
  6. In a single print statement, print the values of the first_name, middle_name, and last_name variables. Write down the full name you expect to print out, then run the script and examine the terminal’s output. Did the names print out like you expected?
  7. Using square bracket notation, add a new key named "job" to the dictionary stored in the person variable and give it an appropriate string value.
  8. Print the value under the "job" key in the person dictionary.
  9. Using square bracket notation, update the value under the "hobby" key to a different string value.
  10. Print the value under the "hobby" key.
  11. Using the pop() method, remove the "last_name" key from the dictionary stored in the person variable.
  12. Print dictionary in the person variable. Run the script and verify the output contains the "first_name", "hobby", and "job" keys; but does not contain the "last_name" key.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20