I was doing some practice tasks from NiO for an upcoming coding competition. The competition is held online and forces me to use stdin.readline so they can test my code. The usage of stdin got me really stuck. The script is running flawlessly with raw_input but throws "ValueError: substring not found" whenever I switch to sys.stdin.readline. Am I doing something stupidly wrong?
import string
import sys
n = int(sys.stdin.readline())
txt = sys.stdin.readline()
ab = string.ascii_uppercase
result = ""
for letter in txt:
result += ab[((ab.index(letter) + n) % 26)]
print result
readline()includes the newline at the end of the string. There's no newline inab, soab.index(letter)fails when you get to the last character.