+ 1

Why the values aren't getting stored in except.txt file!!

#except.txt has been created in the same folder!! print("Welcome To Division Calculator!!\n") with open('except.txt', 'a') as ex: while True: first = input('Enter 1st Number:\n(Enter Q to quit) ') if first == 'Q' or first == 'q': break second = input('Enter 2nd Number: ') try: over = int(first)/int(second) except ZeroDivisionError: print('You cant divide', first,'by 0\n') else: print('\n') print('Your answer is', over, '\n') ex.write(first + '\n') ex.write(second + '\n') ex.write(str(over) + '\n')

19th May 2020, 5:25 PM
Lucky Nayak
Lucky Nayak - avatar
11 odpowiedzi
+ 4
Have you tried this: '\r\n' instead of '\n'
19th May 2020, 6:09 PM
Lothar
Lothar - avatar
+ 6
If you open a file with >with open(...)< files don't have to be closed explicitely, this is done automatically.
19th May 2020, 5:41 PM
Lothar
Lothar - avatar
+ 4
[Edited] On iOS the code works as expected. May be there is an issue that is platform dependend? Are you working on Windows? -> Test on Windows was also successful.
19th May 2020, 5:53 PM
Lothar
Lothar - avatar
+ 2
U should close file. edit: ohhh with....
19th May 2020, 5:33 PM
Oma Falk
Oma Falk - avatar
+ 1
Seems like it works to me: https://code.sololearn.com/cq1h5l14X8lP/?ref=app Try entering: 1 3 1 2 q When you use "with" clause, it automatically takes care of closing the file when it's done. You should end up with: 1 2 0.5 1 3 0.3333 stored in the except.txt file.
19th May 2020, 5:43 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Lohar it worked!! Thank You a lot!!
19th May 2020, 6:39 PM
Lucky Nayak
Lucky Nayak - avatar
+ 1
only \n is not working and its working in your laptop!! this means my tablet's Python IDE has some problems!!
19th May 2020, 6:41 PM
Lucky Nayak
Lucky Nayak - avatar
0
When i use \n in ex.write then its not storing the text in except.txt!!
19th May 2020, 5:39 PM
Lucky Nayak
Lucky Nayak - avatar
0
Im working in tablet!!
19th May 2020, 5:57 PM
Lucky Nayak
Lucky Nayak - avatar
0
i think theres problem in android!!
19th May 2020, 6:05 PM
Lucky Nayak
Lucky Nayak - avatar
0
no let me try
19th May 2020, 6:35 PM
Lucky Nayak
Lucky Nayak - avatar