I had stuck with this task and really need some help.
I have a data in the text file:
John 46.5 Sam 62 Steve 45.5 Nigel 67.1 Karen 55
Henry 55 Alex 42 Graham 82 Hannah 56 Nicola 66
Ruth 81 Carl 90 Ben 66.8
And need to Write a program that can read the data from the text file and output each nameand number pair on a new line like this:
>>>
John : 46.5
Sam : 62
Steve : 45.5
Nigel : 67.1
Karen : 55
Henry : 55
Alex : 42
Graham : 82
Hannah : 56
Nicola : 66
Ruth : 81
Carl : 90
Ben : 66.8
AVERAGE: 62.684615384615384
>>>
I can output the text from the file and separate the elements it contains, but I can't set up the correct output as it is specified in the condition.
f = open("grades.txt", "r")
d = f.read()
f.close()
print(d)
print()
d = d.splitlines()
print(d)
for line in d:
print(line)
line = line.split()
print (line)
print()
If you can give me some advice and help me solve this task, I will be very grateful
Thanks in advance