Please . helpme with this problem


#1




File "python", line 1
I'm the first line of the file!
^
SyntaxError: EOL while scanning string literal
and
Oops, try again. Sorry, but I'm gonna need you to refresh the page! Don't worry your code is saved.


it should have printed the lines -one after the other of this para:-
I'm the first line of the file!
I'm the second line.
Third line here, boss.


my_file=open("text.txt","r")
print my_file.readline()
print my_file.readline()
print my_file.readline()
my_file.close().


#2

You need to open the text file, write on three lines, and then click the save and submit button.


#3

did not get :confused:


#4

They are two files in the codecademy console, so click on the other one and write on three or more lines. :slight_smile:


#5

Some people just creating that file by program. You can try something like this:

try:
    my_file = open("text.txt")
except FileNotFoundError:
    lines = ["I'm the first line of the file!",
        "I'm the second line.",
        "Third line here, boss."]
    f = open("text.txt", "w") # Any time we try to open file for writing (or append) open() will create file, if it doesn't exist
    for line in lines:
        f.write(line + "\n")
    f.close()
    
    my_file = open("text.txt")
finally:
    pass
    # Delete pass and put your code here. File already opened.

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.