0

My question is why any other value is not getting apended?? and Q shouldn't be appended but it is getting appended!! How??

#already an empty file called earn.txt is created in the same directory while True: user = input("Name:\n(Enter 'Q' to quit)\n") if user != 'Q': print('Hello, ' + user) print('Now you are in earn.txt\n') if user == 'Q': break with open('earn.txt', 'a') as earnings: earnings.write(user)

18th May 2020, 4:18 PM
Lucky Nayak
Lucky Nayak - avatar
5 Answers
0
with open('earn.txt', 'a') as earnings : while True: user = input("Name:\n(Enter 'Q' to quit)\n") if user != "Q" : print('Hello, ' + user) print('Now you are in earn.txt\n') earnings.write(user) if user == 'Q': break #this works to write into file as many as you enter until Q. Q is not appended.. This is what you looking...?
19th May 2020, 9:46 AM
Jayakrishna 🇼🇳
0
You are opening file outside while loop.. If you open inside loop, it won't..
18th May 2020, 7:03 PM
Jayakrishna 🇼🇳
0
#if i write like this!! This code is also not working properly!! with open('earn.txt', 'w') as file: a = True while a: b = input("Enter Your Name\n(Type Q to Quit)\n") if b == 'Q': break file.write(b)
19th May 2020, 8:00 AM
Lucky Nayak
Lucky Nayak - avatar
0
Please tell someone please
19th May 2020, 8:00 AM
Lucky Nayak
Lucky Nayak - avatar
0
yaa jay krishna
19th May 2020, 10:42 AM
Lucky Nayak
Lucky Nayak - avatar