Indentation in Python is significant: it controls flow.
So when your
if
and
else
are not indented to exactly the same level, they aren't "part of the same statement" - the
for
loop does not contain the
else
part at all!
Try this:
firstName = input("What is your first name? ")
lastName = input("What is your last name? ")
for fl in firstName:
if fl in lastName:
print("The duplicate character in your First name and Last name is/are: ", list(fl))
else:
print("No duplicate value for First name and Last name")
It's a very stupid way to do things, and it's probably going to bite you many times: make sure that whatever editor you use to edit Python code is set to "replace tabs with spaces" as all whitespace counts as a single space for indentation as far as Python is concerned - which means two lines which look identically indented but which contains spaces for one and tabs for teh other can be treated very, very differently!