0

I'm trying to create a small program in python that asks you to enter a list of number plates separated by commas.

It then converts the string into an array and asks for a second set of number plates (again, separated by commas).

What I want it to do is, once you enter both sets of number plates it should tell you if there are any number plates that match and if so, what they are. I currently have this

print('Enter the first set of number plates')
print('Make sure to separate each plate with a comma')

nbPlateInput = input('\n')
nbPlates = str(nbplateinput)

if ',' in nbPlates:
    splitPlate = nbPlates.split(',')
elif ',' not in nbPlates:
    print('\nYou did not separate all number plates with a comma')
    exit()

print('\nEnter the second set of number plates')

nbPlateInput2 = input()
nbPlates2 = str(nbPlateInput2)

if ',' in nbPlates:
    splitPlate2 = nbPlates2.split(',')
elif ',' not in nbPlates2:
    print('\nYou did not separate all number plates with a comma')
    exit()

if any(word in splitPlate for word in splitPlate2):
    duplicate = any(word in splitPlate for word in splitPlate2)
    print(duplicate)
else:
    print('No Match')
    exit()

Currently, when there is a match it outputs true and when there is not, it outputs 'No match' i want it to output the matching number plate

PS. I am quite new to python so sorry if my code is a bit messy

EDIT: I ended up using this code at the end instead of my 'if any' statement

intersect = list(set(splitplate) & set(splitplate2))
print(intersect)

this prints any values that are the same

0 Answers0