- 2
why only Q is getting printed why not all other words?? Explain Please I require help
#if i write like this!! This code is also not working properly!! #only Q is getting written on file earn.txt !! Why any other thing isn't getting attached to that file(earn.txt) 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)
19 odpowiedzi
+ 2
#use file function (open the file as write mode)
with open('earn.txt','w') as file:
#Use loop to write in file as many times you want and use write() to attach in file called earn.txt
while (1 or True):
b = input()
file.write(b)
#If input is 'Q' or 'q' the loop breaks
if (b == 'Q') or 'q'
break
+ 1
Ahmed hasn't explained!! the only girl is priyal who put her efforts so you get the best tag from me though your code was wrong!!
+ 1
basically the line file.write(b) should be written after the break statement inside the while loop!! thats how code works!! Thanks All
+ 1
Its because of the position of the statements
+ 1
Anyone tell me whether the code satisfies the requirements or not
0
You are changing value of b every time. You need to move file .write(b) in elif function
0
Hey priyal that means while should be written outside of function?
0
#This is the correcter code:
# python3 code.py
with open('earn.txt', 'w') as file:
b = str(input("Enter Your Name\n(Type Q to Quit)\n"))
while b != 'Q':
file.write(b)
b = input("Enter Your Name\n(Type Q to Quit)\n")
0
yaa priya the first code was a error!! let me try those!!
0
by the way why did you write input for b 2times??
0
1st one worked!! let me use 2nd one!! and please explain this code!! please
0
2nd one isnt working!!
0
priyal the code of Ahmad is working not yours
0
why sorry!! chill your explanation was nyc but!!
0
error!! again!!
0
i agree
0
Lucious Erudite Lucky Nayak I don't want the best ans tag.
please put the right code as best ans that person also has put his efforts .
0
The person who has put efforts is you actually!! because ahmad wrote the lines but didn't explain!!