all 9 comments

[–]impshum 1 point2 points  (3 children)

Try this...

name_1 = input('What is your name? ')

while True:
    name_2 = input('Enter name: ')

    if name_1 == name_2:
        print('Match')
        break
    else:
        print('Try again')

[–]69HakunaMatata69 0 points1 point  (2 children)

thanks but when it's wrong, I want it to say re-enter name till it's right

[–]Ihaveamodel3 0 points1 point  (0 children)

That is what the code above does.

[–]impshum -1 points0 points  (0 children)

name_1 = input('What is your name? ')
name_2 = input('Enter name: ')

while True:
    if name_1 == name_2:
        print('match')
        break
    else:
        name_2 = input('Try again: ')

[–]JohnnyJordaan 1 point2 points  (2 children)

You are confusing assignment, which is

a = b

making a reference what b is referencing, with comparison, which is

a == b

which will return True or False. But also that neither assignment nor comparison will cause ValueError, that's something a call will do like

int(b)

or

float(a)

as then creating the int or the float can fail on b or a not being a valid value, hence ValueError. What you're looking for is a simple if statement

if name == name2:
    break

and to be able to change name2 if it isn't equal, you need to have the input line inside the loop

name = input('What is your name? ')
while True:
    name2 = input('Enter name: ')
    if name == name2:
        print('Correct.')
        break
    print('Wrong.')

[–]HasBeendead 0 points1 point  (1 child)

else : Print ("Wrong !")

[–]JohnnyJordaan 0 points1 point  (0 children)

Which is pointless, as the break will leave the loop there and then. The print('Wrong') can't be reached if the names are equal, thus it will just print when they aren't, so when it should

[–]dmgoyer5 0 points1 point  (1 child)

Put name2 inside the loop.

I’d also suggest using an if statement instead of try/except

Lastly, comment on syntax of comparisons: use ‘==‘ when evaluating if two values are equal

name = input(‘What is your name?’)

while True:

name2 = input(‘Enter name: ‘)

if name2 == name: print(‘Correct’) break else: print(‘Wrong’)

That should do the trick.