Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why is python giving me a Syntax error?
- #File called test
- 1 def sanitize(time_string):
- 2 if '-' in time_string:
- 3 splitter = '-'
- 4 elif ':' in time_string:
- 5 splitter = ':'
- 6 else:
- 7 return(time_string)
- 8 (mins, secs) = time_string.split(splitter)
- 9 return(mins + '.' + secs)
- 10
- 11
- 12
- 13 def get_coach_data(filename):
- 14 with open(filename) as f:
- 15 data = f.readline()
- 16 temp1 = data.strip().split(',')
- 17 return(Athlete(temp1.pop(0), temp1.pop(0), temp1)
- 18
- 19
- 20 james = get_coach_data('james2.txt')
- 21 julie = get_coach_data('julie2.txt')
- 22 mikey = get_coach_data('mikey2.txt')
- 23 sarah = get_coach_data('sarah2.txt')
- 24
- 25 print(james.name+"'s fastest times are: " + str(james.top3()))
- 26 print(juliename+"'s fastest times are: " + str(julie.top3()))
- 27 print(mikey.name+"'s fastest times are: " + str(mikey.top3()))
- 28 print(sarah.name+"'s fastest times are: " + str(sarah.top3()))
- 1 class Athlete:
- 2 def __init__(self, a_name, a_dob=None, a_times=[]):
- 3 self.name = a_name
- 4 self.dob = a_dob
- 5 self.times = a_times
- 6
- 7 def top3(self):
- 8 return(sorted(set([sanitize(t) for t in self.times]))[0:3])
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "test.py", line 20
- james = get_coach_data('james2.txt')
- return(Athlete(temp1.pop(0), temp1.pop(0), temp1)
- return Athlete(temp1.pop(0), temp1.pop(0), temp1)
Add Comment
Please, Sign In to add comment