Ask Question
12 February, 07:00

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)

+5
Answers (1)
  1. 12 February, 10:06
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers