- 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)

19th May 2020, 8:16 AM
Lucious Erudite
Lucious Erudite - avatar
19 Answers
+ 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
20th May 2020, 1:41 AM
Jenson Y
+ 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!!
19th May 2020, 9:05 AM
Lucious Erudite
Lucious Erudite - avatar
+ 1
basically the line file.write(b) should be written after the break statement inside the while loop!! thats how code works!! Thanks All
19th May 2020, 9:08 AM
Lucky Nayak
Lucky Nayak - avatar
+ 1
Its because of the position of the statements
19th May 2020, 6:51 PM
ARUNACHALAM P V
ARUNACHALAM P V - avatar
+ 1
Anyone tell me whether the code satisfies the requirements or not
19th May 2020, 6:58 PM
ARUNACHALAM P V
ARUNACHALAM P V - avatar
0
You are changing value of b every time. You need to move file .write(b) in elif function
19th May 2020, 8:25 AM
Shay
Shay - avatar
0
Hey priyal that means while should be written outside of function?
19th May 2020, 8:27 AM
Lucky Nayak
Lucky Nayak - avatar
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")
19th May 2020, 8:28 AM
Ahmed Muhammed
Ahmed Muhammed - avatar
0
yaa priya the first code was a error!! let me try those!!
19th May 2020, 8:31 AM
Lucky Nayak
Lucky Nayak - avatar
0
by the way why did you write input for b 2times??
19th May 2020, 8:34 AM
Lucky Nayak
Lucky Nayak - avatar
0
1st one worked!! let me use 2nd one!! and please explain this code!! please
19th May 2020, 8:36 AM
Lucky Nayak
Lucky Nayak - avatar
0
2nd one isnt working!!
19th May 2020, 8:38 AM
Lucky Nayak
Lucky Nayak - avatar
0
priyal the code of Ahmad is working not yours
19th May 2020, 8:40 AM
Lucky Nayak
Lucky Nayak - avatar
0
why sorry!! chill your explanation was nyc but!!
19th May 2020, 8:50 AM
Lucky Nayak
Lucky Nayak - avatar
0
error!! again!!
19th May 2020, 8:54 AM
Lucky Nayak
Lucky Nayak - avatar
0
i agree
19th May 2020, 9:07 AM
Lucky Nayak
Lucky Nayak - avatar
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 .
19th May 2020, 9:17 AM
Priyal Vyas
Priyal Vyas - avatar
0
The person who has put efforts is you actually!! because ahmad wrote the lines but didn't explain!!
19th May 2020, 10:44 AM
Lucky Nayak
Lucky Nayak - avatar
19th May 2020, 6:57 PM
ARUNACHALAM P V
ARUNACHALAM P V - avatar