fork download
  1. """You can use this class to represent how classy someone
  2. or something is.
  3. "Classy" is interchangable with "fancy".
  4. If you add fancy-looking items, you will increase
  5. your "classiness".
  6. Create a function in "Classy" that takes a string as
  7. input and adds it to the "items" list.
  8. Another method should calculate the "classiness"
  9. value based on the items.
  10. The following items have classiness points associated
  11. with them:
  12. "tophat" = 2
  13. "bowtie" = 4
  14. "monocle" = 5
  15. Everything else has 0 points.
  16. Use the test cases below to guide you!"""
  17.  
  18. class Classy(object):
  19. def __init__(self):
  20. self.items = []
  21.  
  22. def addItem(self, str1):
  23. self.items.append(str1)
  24.  
  25. def getClassiness(self):
  26. sum = 0
  27. for item in self.items:
  28. if (item == "tophat"):
  29. sum = sum + 2
  30. elif (item == "bowtie"):
  31. sum = sum + 4
  32. elif (item == "monocle"):
  33. sum = sum + 5
  34. return sum
  35.  
  36. # Test cases
  37. me = Classy()
  38.  
  39. # Should be 0
  40. print me.getClassiness()
  41.  
  42. me.addItem("tophat")
  43. # Should be 2
  44. print me.getClassiness()
  45.  
  46. me.addItem("bowtie")
  47. me.addItem("jacket")
  48. me.addItem("monocle")
  49. # Should be 11
  50. print me.getClassiness()
  51.  
  52. me.addItem("bowtie")
  53. # Should be 15
  54. print me.getClassiness()
Success #stdin #stdout 0.04s 63592KB
stdin
Standard input is empty
stdout
0
2
11
15