pythonpython-3.xstringpunctuation

How to find punctuation marks in str python


its a kattis problem "Canadians, eh?" if the sentence ends with "eh?" the person is canadian and if not its an imposter this is my code rn

a = input()
found = a.find('e')
found2= a[found + 1]
found3=a[found2 + 1]

if a[found + 1] == 'h' and found3 =='?':
    print("Canadian!")
else : 
    print("Imposter!")

i have no problem with finding "eh" but the it cant find'?' mark giving me an 'can only concatenate str (not "int") to str' error i hope you understood my problem this is the kattis problem link if you wanna check it out https://open.kattis.com/problems/canadianseh


Solution

  • Just try this :

    a = input()
    print("Canadian!" if a.endswith("eh?") else "Imposter!")
    

    Use str.endswith() to check if a string ends with any particular sub-string.