Answer to Question #120606 in Python for samiro Elmi

Question #120606
Write a loop that continually asks the user what pets the user has until the user enters rock, in which case the loop ends. It should acknowledge the user in the following format. For the first pet, it should say You have a dog with a total of 1 pet(s) if they enter dog, and so on.

Sample Run
What pet do you have? lemur
What pet do you have? parrot
What pet do you have? cat
What pet do you have? rock
Sample Output
You have a lemur with a total of 1 pet(s)
You have a parrot with a total of 2 pet(s)
You have a cat with a total of 3 pet(s)
1
Expert's answer
2020-06-09T14:22:00-0400
lst = []
for i in range(10000000):
    n = input("What pet do you have? ")
    if n == "rock":
        break
    else:
        lst.append(n)
    
for i in range(len(lst)):
    print("You have a",lst[i], "with a total of ",i+1,"pet(s)")


This code is valid for range greater than 3. Range can be changed according to the limit of the inputs.



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS