4.2 Code Practice: Question 2
Instructions
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)

Respuesta :

In python 3:

total = 0

while True:

   pet = input("What pet do you have? ")

   if pet == "rock":

       break

   total += 1

   print("You have a {} with a total of {} pet(s)".format(pet, total))

I hope this helps!

fnej

Answer:

pet = input(str("What pet do you have?"))

totalPets = 1

while(pet!="rock"):

  print("You have a " + str(pet) + " with a total of " + str(int(totalPets)) + " pet(s)")

  totalPets = totalPets+ 1

  pet = input(str("What pet do you have?"))

ACCESS MORE
EDU ACCESS