Why won't this code work ? 5/9


#1
my_file=open("text.txt","r+")
my_file.write("I'm the first line of the file!"+"\n")
my_file.write("I m the second line"+"\n")
my_file.write("I am last one"+"\n")
my_file.readline()
my_file.readline()
my_file.readline()
my_file.close()

Why python throws of error while i try to run this....
Error is as follows:

Traceback (most recent call last):
  File "python", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'text.txt'

#2

on this line

my_file=open("text.txt","r+")

The r+ implies that the file already exist and that you want to read and write to it
but the file does not exist so you have to create it.
To do that need to pass

w to write a file and it will create the file if it does not exit
or
w+  to write and read a file and it will create the file if it does not exit

#3

Thannks!!!!...........Awesome