Why the output is empty in the following code
f = open("/storage/emulated/0/Pokemon.txt","w+")
f.write("""A is first letter of Alphabet
B is second letter of Alphabet
C is third letter of Alphabet
D is fourth letter of Alphabet """)
print(f.readline(), end = "")
print(f.readline(), end = "")
print(f.readline(), end = "")
print(f.readline(), end = ""
Is it cuz of w+
mode, cuz when I tried same with r+
mode it’s working but it’s printing first list again at the end.
This is the code
f = open("/storage/emulated/0/Pokemon.txt","w+")
f.write("""A is first letter of Alphabet
B is second letter of Alphabet
C is third letter of Alphabet
D is fourth letter of Alphabet """)
print(f.readline(), end = "")
print(f.readline(), end = "")
print(f.readline(), end = "")
print(f.readline(), end = "")
And this is output
A is first letter of Alphabet
B is second letter of Alphabet
C is third letter of Alphabet
D is fourth letter of Alphabet A is first letter of Alphabet
[Program finished]
Also I noticed a glitch
If I replace w+
with r+
and run the code it gives this output
A is first letter of Alphabet
B is second letter of Alphabet
C is third letter of Alphabet
D is fourth letter of Alphabet
and run again the same code it prints first line again at the end.