I have got a string as is:
line = 'City' /* City can be in 2 or 3 parts */
----> 2 parts: first char of each part is a capital letter.
----> 3 parts: first char of 1st and 2nd part is a capital letter.
The line I get is always valid because I check it with a regex already, I now would like to know what is the best way to ask the user for a character, then check if the input is the same as the City's first character (no matter what part of the city), if it is, print the City name to the output.
I am doing this for now but I'm learning Python for 2 days now and I'm kind of struggling right now.
line_ = "Mont de Marsan"
while True:
inp = input('')
if 'ABORT' in inp:
inp = False
sys.exit(0)
else:
inp = input('')
for c in line_:
if inp == c:
print (line_)
else:
inp = False
sys.exit(0)
break
I hope the description of my problem is straight forward because it's getting messy in my mind :)
Could you please help me find the best way to perform such things in real time and for a lot of strings ?
/* EDIT */
expected behaviour of programm if City is 'Pont de Marsan'
<---- d
----> Mont de Marsan
<---- P
----> Pont de Marsan
<---- M
----> Mont de Marsan
<---- l
program exit.
Here's some more explanation:
I have a list of City, some can be 'Paris', some can be 'Mont de Marsan' or even 'Pont Neuf'. I now have to ask the user for a single character, if he enters P, I have to print 'Paris' and 'Pont Neuf', if he enters 'd' I have to print 'Mont de Marsan'. It's the same behaviour as the GPS system in cars.
string-name[0]. Or you can test withstring-name.istitle()