Respuesta :
Answer:
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
Following are the python program to use the loop to count the number of pets until the user enters the "rock":
Program:
c = 0#defining a variable c that initilzes with 0
p = input()#defining a variable p that input value
while p != 'rock':#defining a loop that check p value not equal to rock
c += 1#using c variable for counts total number of pets
print('You have a %s with a total of %d pet(s)' %(p,c))#print total number of pet
p = input() #input value
Output:
Please find the attached file.
Program Explanation:
- Defining a variable "c" that is initialized with 0, which is used to count input values.
- In the next line, a "p" variable is declared as the input value from the user end.
- A while loop is declared to check that the p-value is not equal to 'rock'.
- Inside this loop, the "c" variable is used for counting the total number of pets, and a print method is used to print the total number of pets.
- Another input method is used that works until the user inputs the value that is "rock".
Find out more about the loop here:
brainly.com/question/17067964