I am quite new to Python3 and I have a hard time coding some stuff using python3.
I want to store the string characters into new variables which I read the new one using the readline()
function in python3.
Below is my code with the input file description.
import sys
sys.stdin = open('../data/lecture.txt')
rl = lambda : (sys.stdin.readline().strip())
for _ in range(int(rl())):{
print(rl())
}
console
abbaaccb
dddcccbbbaaa
geegeegeegeebabybabybaby
oh
As you can see, I opened the lecture.txt
and printed the values inside it using rl()
. When I printed it, it showed the string characters as shown above.
However, when I specified the new variable and stored the characters into it, it throw error indicating syntax error as below
import sys
sys.stdin = open('../data/lecture.txt')
rl = lambda : (sys.stdin.readline().strip())
for _ in range(int(rl())):{
new_variable = str(rl().strip()) //where error occurred
}
I tried to google to resolve my issue but failed.
I attached the input file for your kindly help.
lecture.txt
4
abbaaccb
dddcccbbbaaa
geegeegeegeebabybabybaby
oh
Thanks