Python Forum
why my method doesn't find my List in the same class?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why my method doesn't find my List in the same class?
#1
hello everybody,

I am begginner in python. I wrote the code under and I don't understand why I have the error you can find under

from random import *

class CardGame (object):
    Color = ["heart", "diamond", "club", "spade"]
    Value = [2, 3, 4, 5, 6, 7, 8, 9, 10, "valet", "queen", "king", "ace"]

    def __init__(self):
        self.cards = []
        for A in Value :
            for B in Color :
                self.cards.append((A, B))

    def CardName (self, Card):
        return "{0} of {1}".format(Value[Card[0]], Color[Card[1]])

    def ShuffleGame (self):
        return shuffle(self.cards)

    def TakeCard (self):
        return self.cards.pop()
Error:
Traceback (most recent call last): File "/Users/nic/Desktop/python/Card_Game_2.py", line 22, in <module> Game = CardGame() File "/Users/nic/Desktop/python/Card_Game_2.py", line 9, in __init__ for A in Value : NameError: name 'Value' is not defined
Thanks for your help
Reply


Messages In This Thread
why my method doesn't find my List in the same class? - by Scorpio - Jan-31-2019, 04:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 293 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 822 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  Why doesn't list require global keyword? johnywhy 9 883 Jan-15-2024, 11:47 PM
Last Post: sgrey
  How to read module/class from list of strings? popular_dog 1 499 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Program to find Mode of a list PythonBoy 6 1,163 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,288 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Using one child class method in another child class garynewport 5 1,664 Jan-11-2023, 06:07 PM
Last Post: garynewport
  Find (each) element from a list in a file tester_V 3 1,256 Nov-15-2022, 08:40 PM
Last Post: tester_V
  read a text file, find all integers, append to list oldtrafford 12 3,676 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  find some word in text list file and a bit change to them RolanRoll 3 1,569 Jun-27-2022, 01:36 AM
Last Post: RolanRoll

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020