Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The containers and Repositories of Dr. Moreau this are tge programs 01. You should have already written two Python scripts: one for generating a JSON

The containers and Repositories of Dr. Moreau
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
this are tge programs
01. You should have already written two Python scripts: one for generating a JSON file of assembled animals (generate_animals.py), and another for reading in and printing one animal at (read_animals.py) random. You are almost ready to release this code into the wild for others to use. Your aims in this homework are (1) write one new feature into the read_animals.py script, (2) write a unit test for your new feature in read_animals.py, (3) write a Dockerfile to containerize both scripts, (4) write a reasonable README.md for your repository. More details on each of the requirements: (1) New Feature The read_animals.py script has a lot of room for improvement. Write some new functionality into the script, and write at least one unit test using the unittest library. Some examples of new features that could be added to the script include: Pick two random animals and 'breed' them by mixing their elements to create a new animal, which is printed to screen along with its 'parents' Use the argparse library to take command line arguments and apply some error checking on the input Generate some summary statistics of all the animals read in and print it to screen These suggestions are suggestions only - please be creative and write any new feature into read_animals.py that you want. (2) Unit Test Use the Python unittest library to write at least one test for your new functionality in read_animals.py. (Remember, a single 'test' should probably multiple 'checks' in it - see the section on Unit Testing for examples). The test should be in a file like test_read_animals.py and should be executable from the command line. (3) Dockerfile The scripts we are writing should be runnable directly on ISP. They should also be runnable within a container. (Users downloading your code may want to run them directly, run them in a container, or both - it is usually good practice to provide all these options.) Write and provide a Dockerfile that encapsulates your Python scripts. Any output generated by the scripts should be accessible outside of the container. You do not need to containerize the unit tests. #Generate Animals.py import random import json head_list=['snake','bull''lion', 'raven','bunny'l animals=0] for i in range(20): head=head_list[random.randint(0, len(head_list)-1)] body=head_list[random.randint(0, len(head_list)-1)]+'- '+head_list[random.randint(0, len(head_list) - 1)] arms=random.randrange(2,11,2) legs=random.randrange(3,13,3) tails=arms+legs animals.append({"head":head,"arms":arms, "legs":legs, "tails":tails}) json_data=json.dumps (animals, indent=4) with open("sample.json", "w") as outfile: outfile.write(json_data) Reading and displaying data from json with open('sample.json', 'r') as openfile: json_object = json.load(openfile) print(json_object[random.randint(0, len(json_object))]) import random import json head_list=["snake', 'bull,"lion', 'eaven, "bunny's animals [1 for in range(20) headsheed_list[randon.randint(0, len(head_11st)-1)] body head_listtrandon.randint(e, len(head_list)-1)]+"- thead_listrandon.randint(e, len(head_11st)-1) arrandon.randrange(2,11,2) legs random.randrange(3,13,9) tailsmarssilega animals.append("head":head, arnstars :legs, tadit:tails) json_data-json.dumps(animals, indent-4) with open("complejon", "M) outfilet cutfile.write(json_dute with open('sample.json', 'r') as openfile: json_object json.load(openfile) print(json_object[random.randint(0, len(json_object))]) 01. You should have already written two Python scripts: one for generating a JSON file of assembled animals (generate_animals.py), and another for reading in and printing one animal at (read_animals.py) random. You are almost ready to release this code into the wild for others to use. Your aims in this homework are (1) write one new feature into the read_animals.py script, (2) write a unit test for your new feature in read_animals.py, (3) write a Dockerfile to containerize both scripts, (4) write a reasonable README.md for your repository. More details on each of the requirements: (1) New Feature The read_animals.py script has a lot of room for improvement. Write some new functionality into the script, and write at least one unit test using the unittest library. Some examples of new features that could be added to the script include: Pick two random animals and 'breed' them by mixing their elements to create a new animal, which is printed to screen along with its 'parents' Use the argparse library to take command line arguments and apply some error checking on the input Generate some summary statistics of all the animals read in and print it to screen These suggestions are suggestions only - please be creative and write any new feature into read_animals.py that you want. (2) Unit Test Use the Python unittest library to write at least one test for your new functionality in read_animals.py. (Remember, a single 'test' should probably multiple 'checks' in it - see the section on Unit Testing for examples). The test should be in a file like test_read_animals.py and should be executable from the command line. (3) Dockerfile The scripts we are writing should be runnable directly on ISP. They should also be runnable within a container. (Users downloading your code may want to run them directly, run them in a container, or both - it is usually good practice to provide all these options.) Write and provide a Dockerfile that encapsulates your Python scripts. Any output generated by the scripts should be accessible outside of the container. You do not need to containerize the unit tests. #Generate Animals.py import random import json head_list=['snake','bull''lion', 'raven','bunny'l animals=0] for i in range(20): head=head_list[random.randint(0, len(head_list)-1)] body=head_list[random.randint(0, len(head_list)-1)]+'- '+head_list[random.randint(0, len(head_list) - 1)] arms=random.randrange(2,11,2) legs=random.randrange(3,13,3) tails=arms+legs animals.append({"head":head,"arms":arms, "legs":legs, "tails":tails}) json_data=json.dumps (animals, indent=4) with open("sample.json", "w") as outfile: outfile.write(json_data) Reading and displaying data from json with open('sample.json', 'r') as openfile: json_object = json.load(openfile) print(json_object[random.randint(0, len(json_object))]) import random import json head_list=["snake', 'bull,"lion', 'eaven, "bunny's animals [1 for in range(20) headsheed_list[randon.randint(0, len(head_11st)-1)] body head_listtrandon.randint(e, len(head_list)-1)]+"- thead_listrandon.randint(e, len(head_11st)-1) arrandon.randrange(2,11,2) legs random.randrange(3,13,9) tailsmarssilega animals.append("head":head, arnstars :legs, tadit:tails) json_data-json.dumps(animals, indent-4) with open("complejon", "M) outfilet cutfile.write(json_dute with open('sample.json', 'r') as openfile: json_object json.load(openfile) print(json_object[random.randint(0, len(json_object))])

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

More Books

Students also viewed these Databases questions

Question

What is meant by a billing scheme?

Answered: 1 week ago

Question

4 How can you create a better online image for yourself?

Answered: 1 week ago