Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please don't copy and paste. The answer on other post is wrong. TypeError: string indices must be integers, not ' str ' Thank you

Please don't copy and paste. The answer on other post is wrong.
"TypeError: string indices must be integers, not 'str'"
Thank you
For this project, you will import the json module.
Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you.
The init method takes no parameters and initializes any data members, which must all be private.
The add_pet method takes as parameters the name of the pet, the species of the pet, and the name of the pet's owner. If a pet has the same name as a pet that has already been added, then the function should raise a DuplicateNameError and not add the pet (you'll need to define this exception class).
The delete_pet method takes as a parameter the name of the pet and deletes that pet.
The get_owner method takes as a parameter the name of the pet and returns the name of its owner.
The save_as_json method takes as a parameter a filename and uses that name to save the Pet data currently in memory, in JSON format. You can assume the file extension (if any) will be part of the name that is passed in. You can organize your JSON file however you want.
The read_json method takes as a parameter the name of a file to read and loads that file. This will replace all of the pets currently in memory.
The get_all_species method takes no parameters and returns a Python set of the species of all pets.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions