Mar-26-2019, 06:17 PM
# I Write a program to append the times table for our poem in sample.txt .So , this is all of my code
numbers = 1 for i in range(2, 12): while 13 >= numbers > 0: multiply = numbers * i print('| {0} Times {1} is {2} '.format(numbers, i, multiply)) numbers += 1 print('=' * 21) with open('times_table.txt', 'w') as times: for table in times: print(table, file=times)And the output is :
Output:| 1 Times 2 is 2
| 2 Times 2 is 4
| 3 Times 2 is 6
| 4 Times 2 is 8
| 5 Times 2 is 10
| 6 Times 2 is 12
| 7 Times 2 is 14
| 8 Times 2 is 16
| 9 Times 2 is 18
| 10 Times 2 is 20
| 11 Times 2 is 22
| 12 Times 2 is 24
| 13 Times 2 is 26
========================================
But because of code at the end lines for files appending , I'm facing this error below :Error:Traceback (most recent call last):
File "C:/Users/debug system/IdeaProjects/LearnPY/02/I_O - Challenge.py", line 11, in <module>
for table in times:
io.UnsupportedOperation: not readable
So , finally I don't know how to append this time table stuffs into a sample.txt file .I really appreciate you all guys . If you can possibly help me with this .
Thanks .