Question
I'm just trying to figure out why I'm getting 2 extra lines in my output. Can someone figure this out for me please? #open, write,
I'm just trying to figure out why I'm getting 2 extra lines in my output. Can someone figure this out for me please?
#open, write, and read text file (e.g., "WordTextFile1.txt") using open(), write(), read()
file_name = (input())#store name of the file
with open(file_name,'r') as f:
word1 = str(f.read())
word2 = str(f.read())
word3 = str(f.read())
#solution accepts file input to insert sentence composed of file content into text file on a new line
f = open(file_name,"r")
lines = f.read().splitlines()
lines=' '.join(lines) lines = lines.replace(' ', '')
f.close();#close the file
#solution outputs the text file contents including the new sentence
print(f"{word1} {word2} {word3} {lines}")
Output is nearly correct, but whitespace differs. See highlights below Input Your output Expected outputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started