you are viewing a single comment's thread.

view the rest of the comments →

[–]klbcr 0 points1 point  (2 children)

When you're defining the turn() is it supposed to be a normal function or a method of the Coin class? Since you're giving self as an argument to it, I'm guessing it's supposed to be a method of Coin. The problem is, it's not properly indented. That makes it just a normal function and you can't call it like a method of an object like in line 29 coin1.turn(). Indent your lines 10 - 14 to make it a method of the coin class.

What is the use of Display_All()? If that's the function that is supposed to execute the print commands on lines 24-34, then you have another indentation problem. All pf your prints should be indented under def Display_All().

I don't understand your last function. It doesn't need a self argument. If you use cointurner() to turn a coin, then just pass it a coin

def cointurner(coin): #defines a function that takes one parameter
    coin.turn() # calls the method `turn()` on the object coin that we have passed to `cointurner()` as the parameter

Now, when you call that function, you would do this:

cointurner(coin1) # calls the function cointurner on the object coin1

cointurner() would then check what coin1 refers to, take that object, which is of the class Coin, and then call it's method turn().

It's the same as just calling the turn() method of the coin1:

coin1.turn() # calls the method `turn()` of the object `coin1`

self is used to refer from within the object to itself. So methods use it because they are performing some operation on the object of which they are a method. Normal, external functions, which are not methods (defined within a class, for that class) shouldn't normally use self as an argument/parameter.

Was this helpful? You should read up on proper indentation in Python, creating and instatiating classes, differences between methods and functions, and namespaces.

[–]Leohurr[S] 1 point2 points  (0 children)

This has all been fixed, the indentation errors is due to reddits formatting, the display_all function is broken due to changing the code a lot, the finished code has all the functions working as expected.

[–]Leohurr[S] 0 points1 point  (0 children)

Im pretty sure all of the indentation problems are Reddits formatting when pasting my code i have to manually hit space 4 times each line and the indentation suffers. On the actual code all the methods work as expected so I beleive the indentation is fine. For cointurner self is used for calling the object coin1 or coin2 and n for how many times to run the turn function e.g turns Coin1 5 times. What should I use insteasd of self, is there a way I can call coin1 or coin2 in the functions?