Answer to Question #305453 in Python for Pyara

Question #305453

Write a program with a loop that repeatedly reads a string as input, where the string is either "duck" or "goose". The loop terminates when "goose" is entered. After the loop, your code should print out the number of "duck" strings that were read.


NOTE: When reading the input, do not display a prompt for the user. Use the input()function with no prompt string. Here is an example:


bird = input()


1
Expert's answer
2022-03-03T09:59:39-0500
i = True
j = 0
while i:
    n = input('')
    if n == 'goose':
        break
    elif n != 'duck':
        print('only goose or duck is allowed')
        break
    else:
        j = j + 1
print(j)

duck
duck
goose
2

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS