I am a beginner at python. I have a code that reads a text file from my computer and converts all the text to int. I am struggling with the last few lines in the analyze golf scores function.
I need to tell the code that for a score under 280 to take these values and get the amount, which I know to use Len(score) for but I am going wrong with getting the values in the first place. It should print the number of scores below 180, but I keep getting errors and I am so lost! Any help is appreciated at all! Thank you so much!!!
My error is in the last six lines of code! I don't know how to get it to read the values under 280 in the list :(
The error is:
TypeError: '<' not supported between instances of 'str' and 'int'##
on the line:
if score < 280:
def open_and_read_golf_scores():
raw_scores = open("golfscores.txt", "r")
scores = []
for current_line in raw_scores:
values = current_line.split(",")
scores.append(values[2])
raw_scores.close()
return scores
def analyze_golf_scores():
scores = open_and_read_golf_scores()
total = 0
for score in scores:
score = score[0:3]
total = total +int(score)
ave = total/len(score)
print("Average score =", ave)
for score in scores:
if score < 280:
scores.append(values)
below_par = total + len(score)
print("The number of scores below par is ", below_par)
scoresorvaluesare. And you still haven't included your error. :(