0

I am creating a program in Python which asks the user to enter their name. I am also trying to verify this by letting the user type it on twice and the program would only run if the user enters their name correctly twice.

Please have a look at the code below and please provide me with any suggestions

from random import randint 
name3 = 1

while name3 == -1:
    name = input("Please enter your name ")
    name1 = input("Please enter your name again for verification ")

    if name == name1 :
        print("you may now start the quiz")
    else:
        print (" The two names are different please enter you your name again")
        name3 = name3 + 1
Bas Peeters
  • 3,269
  • 4
  • 33
  • 49

1 Answers1

0

Hi this is a simple model to check the username and limit the number of retry

name = raw_input("Please enter your name ")
name1 = raw_input("Please enter your name again for verification ")

retry_count = 0
while (name != name1):
    retry_count += 1

    print ("The two names are different please enter you your name again!")
    name = raw_input("Please enter your name ")
    name1 = raw_input("Please enter your name again for verification ")

    if (retry_count > 3 ):
        break
if (retry_count > 3):
    print("Too many retry!")
    # do something
else:
    print("you may now start the quiz")
vasilenicusor
  • 2,023
  • 1
  • 21
  • 37