Ask Question
10 July, 12:25

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:

User enters:

lemur parrot cat rock

Outputs:

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)

+3
Answers (1)
  1. 10 July, 13:13
    0
    Check the explanation

    Explanation:

    The Python program that frequently asks the user what pets the user has,

    until the user enters "rock", in which case the loop ends can be analysed in the written codes below.

    '''

    # count of pets

    count = 0

    # read the user input

    pet = input ()

    # loop that continues till the user enters rock

    # strip is used to remove the whitespace

    while pet. strip () ! = 'rock':

    # increment the count of pets

    count + = 1

    # output the pet name and number of pets read till now

    print ('You have a %s with a total of %d pet (s) ' % (pet. strip (), count))

    pet = input () # input the next pet

    #end of program
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers