excess blank line is printing

Question:

so I want to read a text file and print its all content in uppercase
character. I written the code and it’s correct also. But I don’t know
why the excess blank line is printing between the two line.

import pickle
file=open("STORY.TXT",'r')
string=file.readlines()
for x in string:
    print(x.upper())
file.close()

output

@AN ORANAGE IS WRONG

@WRONG

@APPLE 

@IS GOOD

@FOR YT IN SE

@AA

@AA 

desired output

@AN ORANAGE IS WRONG
@WRONG
@APPLE 
@IS GOOD
@FOR YT IN SE
@AA
@AA
Asked By: Sahil Panhalkar

||

Answers:

When you use .readlines without arguments you get trailing newlines, print add newlines by default, hence blank lines. You should instruct print to not add anything, that is do

file=open("STORY.TXT",'r')
string=file.readlines()
for x in string:
    print(x.upper(),end="")
file.close()
Answered By: Daweo
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.