I am currently trying to now utilize an if statement that checks the score values set in a file that was read earlier as a par value. I am currently unsure of how to have the data be read as specific integers as those values were previously converted to string values in an earlier portion of the assignment. Where would I want to initially start?
I have currently managed to have the program read the .txt files made initially in the beginning part, however, I currently am unsure of how to handle this initial program in regards to converting the final numerical values back to normal, nor am I sure how to get it to properly cycle to check each specific record's final data piece.
This is the data the program pulls from:
Andrew,Marks,11.2,72.0
Betty,Franks,12.8,89.0
Connie,William,14.6,92.0
Donny,Ventura,9.9,78.0
Ernie,Turner,10.1,81.0
Fred,Smythe,8.1,75.0
Greg,Tucker,7.2,72.0
Henry,Zebulon,8.3,83.0
Ian,Fleming,4.2,72.0
Jan,Holden,7.7,84.0
Kit,Possum,7.9,79.0
Landy,Bern,10.3,93.0
Mona,Docker,11.3,98.0
Kevin,Niles,7.1,80.0
Pam,Stiles,10.9,87.0
Russ,Hunt,5.6,73.0
The Program designed to pull the data from the file and run it in the if statement is this:
infile = open('golf.txt', 'r')
golf = infile.readlines()
for elements in golf:
int(golf[elements[3]])
if golf[elements[3]] > 80:
print(elements, 'Score: Over Par')
elif golf[elements[3]] == 80:
print(elements, 'Score: At Par')
elif golf[elements[3]] < 80:
print(elements, 'Score: Under Par')
infile.close()
I was expecting it to print the individual lists, alongside stating the score was "over par", "under par", or "At Par" dependent on what the final value in each list inside the external list, however I receive this error instead:
Traceback (most recent call last):
File "C:/Users/joelc/PycharmProjects/Project2/File/JoelLab5Pt2.py", line 7, in <module>
int(golf[elements[3]])
TypeError: list indices must be integers or slices, not str
Aucun commentaire:
Enregistrer un commentaire