CodeSolved

A comprehensive source of programming questions and exercises

Save information in the file

Practice Easy 11/ Download 2389 Views

Write a program thatStudent Name and NumberReceive users and in a file namedStudents.txtSave. Also, after each storage, display the entire information of this file at the output.

12 Answers

name = input('name: ')
code = input('code: ')
f = open('students.txt', 'a')
f.write(name + '\n')
f.write(code + '\n')
f.close()
f = open('students.txt', 'r')
print(f.read())
f.close()
import os
def save_student_data():
with open('student.txt','w') as file:
while 1:
name=input('enter student name(for end enter exit):')
if name.lower()=='exit':
break
student_id=input('enter student number:')
file.write(f'{name},{student_id}\n')
file.flush()
file_size=os.path.getsize('student.txt')
print(f'file size saved:{file_size}bite')
save_student_data()
Maryam.n Download Python
<< Previous page 1 2 Next Page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×