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)
5 Réponses
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...?
0
You are opening file outside while loop.. If you open inside loop, it won't..
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)
0
Please tell someone please
0
yaa jay krishna