Ask 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 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)

+1
Answers (1)
  1. 12 December, 12:59
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers