Guest User

Untitled

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