Answer to Question #159796 in Python for Meera

Question #159796

#(a) Write a program that keeps asking the user for their name until they enter "Tim". Otherwise, keep saying "You are not Tim!" and ask for their name.

#(b) Allow your name as a valid input as well.

#(c) Keep track of how many times the user fails to enter the correct name, and report it when they finally get it right. (2K, 2C)


1
Expert's answer
2021-01-31T18:57:30-0500
name = input('Enter your name: ')  #ask user to input name
count = 0   #initialize counter of fails


#keep asking while Tim or YourName (replace it with your real name) are entered
while (name != 'Tim') and (name != 'YourName'):
    print("You are not Tim!")   #print warning
    name = input('Enter your name: ')   #ask for input
    count += 1    #increment number of fails


print("You failed {} times".format(count))

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