I have been trying to create a program which asks for a name and an age and stores them to a text file. My code is as follows:
name_age=open('Name Age.txt','a')
print('1. Writing to a text file')
print('2. Reading a text file')
print('3. Sorting')
Choice=int(input('What do you want to do: '))
if Choice==1:
Name=input('What is the Name: ')
Age=int(input('What is the age: '))
Name_Age=Name,Age
name_age.write(repr(Name_Age),'\n')
print('Written result')
if Choice==2:
name_age=open('Name Age.txt','r')
print('Reading the file')
print(name_age.read(1000))
if Choice==3:
print('Sorting')
print('1. Alphabetical')
print('2. Age')
Choice=int(input('How do you want to sort(1/2): '))
if Choice==1:
print('Sorting Alphabetically')
print(sorted(name_age))
if Choice==2:
print('Help Me HERE')
#I Need Help here... How do you sort the textfile with the ages???
Then my code has the ability to allow the user to read the file from the program and sort the results. I can sort the results alphabetically but I cannot sort them in age order. Can you please help me do this