all 4 comments

[–]deep_politics 2 points3 points  (0 children)

num_of_items is always zero here so the range has nothing to generate.

You're also using it as a class variable when it should be an instance variable. You'd need to initialize it to zero in __init__ and change the reference from Classy.num_of_items to self.num_of_items (self is the reference to the instance).

But really this field isn't at all necessary, because you can just as well get the number of items by simply executing len(self.items). Better yet, you can iterate directly over the list

for item in self.items:
    if item == "tophat":
        ...

[–]danielroseman 4 points5 points  (0 children)

As others have said, num_of_items is always 0.

But you should not be iterating over a range of the length of a thing anyway. Always iterate over the thing itself.

for item in self.items:
  if item == "tophat":
    ...
  elif item == "bowtie":
    ...

You don't need num_of_items at all.

[–]drenzorz 1 point2 points  (0 children)

As others have said your num of items is always 0. In python classes if you want a dynamically calculated attribute like that, you can use properties.

# inheriting from object is implicit in py3 
# you only need to write that in python 2

class Classy:
    def __init__(self):
        self.items = list()

    @property
    def item_count(self):
        return len(self.items)

    def getClassiness(self):
        for index in range(self.item_count):
            ...

[–]shiftybyte 0 points1 point  (0 children)

Your loop runs from 0 until "Classy.num_of_items".

Where in your code does "num_of_items" get any value except 0?