Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Code repeats twice when ran

Hi I am following along during this section and I noticed when I run my code, it repeats twice. Here is an example:

few notes: I am running this in Pycharm, named my file OOP

'''python

import random

class Paladin: Holy = True

def heal(self):
    if self.Holy:
        return (random.randint(1,10))
    return False

from OOP import Paladin

Nathan = Paladin()

print(Paladin.heal(Nathan))

'''

Result: 5 8

It runs twice and I cannot figure out why.

1 Answer

Steven Parker
Steven Parker
243,253 Points

I'm not sure about the "twice", but that's not the normal syntax for invoking and instance method. It should be:

print(Nathan.heal())

And for easier sharing, move your project to a workspace and when you need help you can make a snapshot of your workspace and post the link to it here.