1. Initialize an empty list named pets . 2. Use a while loop to ask the user to add to the list . ( You can stop the loop either on an empty string or by asking if they want to continue 3. Sort the list . 4. Use a for loop to display the updated , sorted list . 5. Print the number of pets in the list after the list of pets is printed . Remember your heading comments - name , date , activity description .

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 18SA
icon
Related questions
Question
1. Initialize an empty list named pets . 2. Use a while loop to ask the user to add to the list . ( You can stop the loop either on an empty string or by asking if they want to continue 3. Sort the list . 4. Use a for loop to display the updated , sorted list . 5. Print the number of pets in the list after the list of pets is printed . Remember your heading comments - name , date , activity description .
osmos#main.py
ntineAptCosmos 2
> RE
main.py
Ctrl Ent
print ("List of pets")
Pets=['dog', cat', 'elephant', bird', 'ferret']
Pets.sort (reverse-True)
for i in range (len(pets):
Print(i+1, pets[i])
Print ()
Print(ʻ-'*50)
4
9.
8.
Count=0
6.
for pet in pets :
10
Count +=1
11
print(count, pet)
input ("Enter a pet type (nothing to stop):")
pet
while pet !="":
pets.append (pet)
12
13
14
pet
input ("Enter a pet type (nothing to stop) :")
15
!!
16
if pet ==**:
17
break
pets.sort()
for pet in pets :
print (pet)
print ("Thère are", len (pets), "pets in the list .")
18
19
20
21
Transcribed Image Text:osmos#main.py ntineAptCosmos 2 > RE main.py Ctrl Ent print ("List of pets") Pets=['dog', cat', 'elephant', bird', 'ferret'] Pets.sort (reverse-True) for i in range (len(pets): Print(i+1, pets[i]) Print () Print(ʻ-'*50) 4 9. 8. Count=0 6. for pet in pets : 10 Count +=1 11 print(count, pet) input ("Enter a pet type (nothing to stop):") pet while pet !="": pets.append (pet) 12 13 14 pet input ("Enter a pet type (nothing to stop) :") 15 !! 16 if pet ==**: 17 break pets.sort() for pet in pets : print (pet) print ("Thère are", len (pets), "pets in the list .") 18 19 20 21
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Mergesort
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning