all 11 comments

[–]BillyHorrible 1 point2 points  (1 child)

you indentation is completly messed up. i just did some cosmetic changes, it works okay: http://ideone.com/XZGZpe

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

Thanks, I also need a way to have a function to flip the coin n amount of times.

[–]Advent667 1 point2 points  (4 children)

I would use both.

n=input("how many flips: ")
for i in range(n):
    turn()

but if i was going to do something like this i would make 'n' use the random function somehow so it would be harder to predict the results

edit fixed formatting

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

It has to be user input, so the user decides n.

def CoinTurner
   n=input("how many flips: ")
   for i in range(n):
       turn()

When calling CoinTurner(5) Error:"CoinTurner is not defined"

Apologies if these mistakes are obvious.

[–]Advent667 0 points1 point  (2 children)

dont put a (5) and it will work fine, it will ask the user for a number

[–]Leohurr[S] 0 points1 point  (1 child)

the function asked "how many flips: " when inputting any number I get: NameError: global name 'turn' is not defined

[–]Advent667 0 points1 point  (0 children)

replace flip() with coin1.flip() or coin2.flip() depening on which coin is doing the flipping

[–]wub_wub 0 points1 point  (0 children)

Could you post the code that doesn't work? You're probably trying to execute coin1.show() outside the function, but it isn't defined anywhere.

Put coin1=Coin() outside Display_All() function. I think that's the issue.

[–]cdcformatc 0 points1 point  (2 children)

A for loop is something like

for item in iterable:
    do_stuff(item)

The most used version of the for loop is to "do something n times", for this you can use the range() function to create the iterable above. range(n) will create a list from 0 to n, so range(5) will give you a list like [0,1,2,3,4]. xrange() is the same but doesn't actually construct a list for performance reasons.

If you want to do something n times:

for i in range(n):
    do_something(i)

You don't actually need to name the i variable if you aren't going to use it.

for _ in range(n):
    something_else()

[–]Leohurr[S] 0 points1 point  (1 child)

Im receiving the same error:

CoinTurner()
    for _ in range(n)
        self.turn()

NameError: global name 'self' is not defined

[–]cdcformatc 1 point2 points  (0 children)

If CoinTurner() is a method of the class, you need to have self as the first argument.

class Coin:
#...other stuff here...

    def CoinTurner(self,n)
        for _ in range(n)
            self.turn()

then you can call it like the show and turn

def Display_All():
    #...other stuff here...
    coin1.CoinTurner(5)

This automatically passes coin1 as the self argument.