Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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}")

image text in transcribed

Output is nearly correct, but whitespace differs. See highlights below Input Your output Expected output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. SCC Soft Computer

Answered: 1 week ago

Question

It is preferable to have a masters degree or a CBA certificate

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago