code_projects_python/STEP1_Basics/6_Files/main.py

39 lines
597 B
Python

a = int(input('Enter a: '))
b = int(input('Enter b: '))
matrix = [
[a, a+1],
[b, b+1]
]
first = True
for line in matrix:
#for el in line:
if first == True:
f_str = f'{line[0]} {line[1]}\n'
first = False
else:
s_str = f'{line[0]} {line[1]}\n'
# Write lines
with open('file', 'w') as f:
f.write(f_str)
f.write(s_str)
f.close()
readed_matrix = []
with open('file', 'r') as f:
for x in f:
if x == '' or x == '\n':
continue
x = x.replace('\n', '')
vals = x.split(' ')
readed_matrix.append(vals)
f.close()
print(f'''
Original matrix:
{matrix}
Readed matrix:
{matrix}
''')