My concern is written below:
Why does this code return this error?
import random with open('rn.txt', 'w') as f: for i in range(10): number = random.random() f.write(str(number) + '\n') content=f.read() print (content)
Error:
Traceback (most recent call last) <ipython-input-11-ddb88b6f5426> in <module> 4 number = random.random() 5 f.write(str(number) + '\n') ----> 6 content=f.read() 7 print (content) UnsupportedOperation: not readable
Why does this code write only a single value to the file?
import random for i in range(10): with open('rn.txt', 'w') as f: number = random.random() f.write(str(number) + '\n') content=f.read() print (content)
This code is supposed to generate 10 random numbers and write them to the file
rn.txt
. What am I doing wrong?