Skip to content

Instantly share code, notes, and snippets.

@NickyAlan
Last active July 14, 2022 14:25
Show Gist options
  • Save NickyAlan/dcc2050ae5bfb70df813c8b8085ba3f4 to your computer and use it in GitHub Desktop.
Save NickyAlan/dcc2050ae5bfb70df813c8b8085ba3f4 to your computer and use it in GitHub Desktop.
NO_STUDENT = int(input('number of student : '))
def write_file(no_student=NO_STUDENT):
with open('std.txt', 'w') as file :
for student in range(no_student) :
fname,lname, age = input(f'student {student+1} : ').split()
file.writelines(f'{fname} {lname} {age}\n')
print(f' -- add : {fname} {lname} {age}')
def del_select_age(del_age=None):
print()
with open('std.txt', 'r') as file :
students = []
if not del_age :
del_age = int(input('\nAge to delete : '))
for student in range(NO_STUDENT) :
fname,lname, age = file.readline().split()
if int(age) != del_age :
students.append(f'{fname} {lname} {age}')
else :
print(f' -- delete : {fname} {lname} {age}')
with open('std.txt', 'w') as file :
for student in students :
file.writelines(f'{student}\n')
write_file()
del_select_age()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment