Class Notes (837,484)
Canada (510,274)
CSC108H1 (113)
Lecture

december 05 notes

2 Pages
130 Views
Unlock Document

Department
Computer Science
Course
CSC108H1
Professor
Michelle Craig
Semester
Fall

Description
 Event class 1. class Event(object): # object = parent class, most classes = objects, 2. # gets basic methods from object class 3. „‟‟Class to represent a single event for my calendar.‟‟‟ 4. 5. def __init__(self, name, start_time = 9, end_time = -1): # double underscores = already 6. „‟‟Create a new Event.‟‟‟ # included, until replaced 7. 8. self.start = start_time 9. if end_time < 0: 10. self.end = start_time + 1 11. else: 12. self.end = end_time 13. self.name = name 14. 15. def rename(self, new_name): 16. „‟‟change the name of this een to str new_name.‟‟‟ 17. 18. self.name = new_name 19. 20. def duration(self): 21. „‟‟Return the number of hours‟‟‟‟ 22. 23. return float(self.end – self.start) 24. 25. def make_all_day(self): 26. „‟‟change this eent to run from 9 to 5‟‟‟ 27. 28. self.start = 9 29. self.end = 17 30. 31. def my_string(self): 32. „‟‟Return a string representation of this object.‟‟‟ 33. 34. name = self.name + „: from „ + str(self.start) + „ to „ + str(self.end) 35. return name 36. # or this: 37. # return „%s: from %f to %f‟ %(self.name, self.start, self.end) 38. 39. def _ _str_ _(self): # the built in string representation of an object 40. „‟‟Return a string representation of this object.‟‟‟ 41. 42. name = self.name + „: from „ + str(self.start) + „ to „ + str(self.end) 43. return name 44. # takes values in tuple and inserts into string %s = string, %d = number, %f = float 45. # or this: 46. # return „%s: from %f to %f‟ %(self.name, self.start, self.end) 47.
More Less

Related notes for CSC108H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit