Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Directions 1. Create the program allMyCats2.py as described on page 85. (83 in the 2nd Edition). 2. Modify the program to sort the list in

image text in transcribedimage text in transcribed

Directions 1. Create the program allMyCats2.py as described on page 85. (83 in the 2nd Edition). 2. Modify the program to sort the list in alphabetical order prior to it being printed. 3. Ensure to test your program and ensure that it works properly. 4. See below for an output example. 5. Submit the allMyCats2.py file into the Chapter 4 Assignment 1 Submission Folder. Example Output (using Python Version 3.6) >>> Enter the name of cat 3 Python 3.6.4 Shell X File Edit Shell Debug Options Window Help Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license ()" for more information. RESTART: G:\TTC Courses\cpt180\Assignments\allMyCats2.py Enter the name of cat 1 (Or enter nothing to stop.) Tom Enter the name of cat 2 (Or enter nothing to stop.) Jerry (Or enter nothing to stop.) Felix Enter the name of cat 4 (Or enter nothing to stop.) Sam Enter the name of cat 5 (Or enter nothing to stop.) Fluffy Enter the name of cat 6 (Or enter nothing to stop.) Tabby Enter the name of cat 7 (or enter nothing to stop.) The cat names are: Felix Fluffy Jerry Sam Tabby Tom | catName6 . input() print("The cat names are:') print(catName1 + + catName2 + ' ' + catName3 + ' ' + catName4 + catNames + + catName) Instead of using multiple, repetitive variables, you can use a single variable that contains a list value. For example, here's a new and improved version of the allMyCatsl.py program. This new version uses a single list and can store any number of cats that the user types in. In a new file editor win- dow, enter the following source code and save it as allMyCats2.py: catNames = [] while True: print("Enter the name of cat' + strlen(catNames) + 1) + (or enter nothing to stop.):') name = input() if name - break catNames - catNames + [name] # list concatenation print("The cat names are:') for name in catNames: print('+ name) When you run this program, the output will look something like this: Enter the name of cat 1 (Or enter nothing to stop.): Zophie Enter the name of cat 2 (Or enter nothing to stop.): Pooka Enter the name of cat 3 (Or enter nothing to stop.): Simon Enter the name of cat 4 (Or enter nothing to stop.): Lady Macbeth Enter the name of cat 5 (Or enter nothing to stop.): Fat-tail Enter the name of cat 6 (Or enter nothing to stop.): Miss Cleo Enter the name of cat 7 (Or enter nothing to stop.): The cat names are: Zophie Pooka Simon Lady Macbeth Fat-tail Miss Cleo You can view the execution of these programs at https://autbor.com /allmycatsl/ and https://autbor.com/allmycats2/. The benefit of using a list is that your data is now in a structure, so your program is much more flexible in processing the data than it would be with several repetitive variables

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_2

Step: 3

blur-text-image_3

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

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions