-1

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

1
  • Why are you searching for e, h and ? separately? I suggest investigating endswith()
    – SiHa
    Commented Dec 28, 2022 at 16:23

2 Answers 2

0

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.

0
0
if a[-3:]=='eh?':
 return 'Canadian!'
else:
 return 'Imposter!'
1
  • @AnkitSharma it does provide the answer. 'If' condition is checking the last three characters and vice versa Commented Dec 28, 2022 at 19:44

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.