Trouble Using Equality Operator To Check If A User Input Is The Same As A Line From A Text File In Python
Just started to learn Python again since finishing my GCSEs two years ago. I've got a bit of background in C# but am having difficulties making a simple program work. The program i
Solution 1:
with
wholequiz = quiz.readlines()
you get a list of lines with newline (\n
) at the end. The comparison cannot succeed unless you do:
a1 = wholequiz[1].rstrip()
That method is useful when you're reading line by line, but since you're reading the whole file at once, you could also do:
wholequiz = quiz.read().splitlines()
then no need to strip for linefeed. Of course, if there's a trailing space in the file that won't remove it (the rstrip
method does)
Post a Comment for "Trouble Using Equality Operator To Check If A User Input Is The Same As A Line From A Text File In Python"