I've tried anything I can think of for "Task 1" which is written in the green comment. Also, when I downloaded "sample.txt" it downloaded as "sample-1.txt" as its name but I'm not sure if it needs the second ".txt" in the code. Thank you.
Code:
"""Task 1: Write a program to read each line from the file sample.txt, and print your original contents of the file.
Task2: Add the following line to the sample.txt file :
"Aaron Woods 1122 123 324 45 88 1561 9 18"
and print your new updated file.
Task 3: Define a function that returns a list that contains information as follows:
[['Cobb' , 'Ty' , 3747.5],[],..,['Smoltz' , 'John' , 293.5],['Woods' , ' Aaron' , 624.00]]
where , 3747.5 is an average calculated by:
Ty Cobb => avg = (13099+11434+3053+724+295+117+1249+9)/8
Same way calculate average for all other players and build the list in the function and return that to main.
Also, note that the last name and first name positions have changed.
Task4: Sort the new list returned by the function, such that the player having least average is printed first and the highest average is printed last."""
#Task 1
file = open("sample-1.txt.txt", "w")
print(file)
file.close()
.txt.txt, so that shouldn't appear in your code.