In: Computer Science
PROBLEM 5: Code for the Ages Function Name: goldenAges()
The coding language is Jes Python
Parameters: ● list1: a list containing the names of the TAs ● list2: a list containing the ages of the TAs
Return Value: none
Description: I have to concede defeat. It's pretty hard to be creative and reference memes when working with File I/O, so you guys will get to learn something about us you might not already know: our ages!! For this problem, write a function that takes in two lists and writes to a file called "TAages.txt". The function should match the ages to the correct TA and write sentences which say how old each TA is on separate lines. The TA names should be written to the file in reverse order, and the ages written in the same order as your parameter. Remember to close your file at the end!
Test Cases: >>>goldenAges(["Genevieve","Tanya","Khalil","Ryan","Christina"],[19,21,22,21,19])
Code:

Code as text:
# function to take list and write to files
def goldenAges(TAnames, TAages):
f = open("TAages.txt", 'w') #open file
list_length = len(TAnames) #get length of lists
for i in range(list_length):
r = list_length - i - 1 # index from end
f.write("TA %s is %d years old.\n" %
(TAnames[r], TAages[i])) #write to file
f.close() #close file
# test
goldenAges(["Genevieve", "Tanya", "Khalil", "Ryan", "Christina"],
[19,21,22,21,19])
Sample run Output file:

P.s. Please ask any doubts in comments and rate the answer