from card import *
from CardCollection import *
def main():
Player1 = input("Player 1, what is your name?: ") # Gets the first players name
print("Ok, thanks " + Player1) # Shows them that I got their name
Player2 = input("Player 2, what is your name?: ")
print("Got it, good luck " + Player2)
playingDeck = CardDeck() # Generates a deck of 52 cards
playingDeck.shuffle() # Uses the shuffle method to put the cards in a random order
Player1hand = playingDeck.deal(15) # Deals out to Player1
Player2hand = playingDeck.deal(15) # Deals out to Player2
Methods will not work within function
Page 1 of 12 Replies - 446 Views - Last Post: 29 November 2012 - 12:47 AM
#1
Methods will not work within function
Posted 28 November 2012 - 10:15 PM
Im writing a main function using classes from another file, and when I put the code in a function it does not work, but when I leave it out it works fine. For Example I had
Replies To: Methods will not work within function
#2
Re: Methods will not work within function
Posted 28 November 2012 - 10:21 PM
I'm guessing (because you only posted a little code with lots of errors in it) you're having trouble because playingDeck is local to the scope of the main function. Not outside of it.
and Player1hand and Player2hand aren't ever defined.
>>> def main(): ... thing_local_to_main = True ... >>> main() >>> thing_local_to_main Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'thing_local_to_main' is not defined
and Player1hand and Player2hand aren't ever defined.
This post has been edited by Python_4_President: 28 November 2012 - 10:22 PM
#3
Re: Methods will not work within function
Posted 29 November 2012 - 12:47 AM
This was an accidental post
Look at my other post with the same title if you can
Look at my other post with the same title if you can
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|