I'm trying to create a Python version of Monopoly. I have a separate class that I am using to shuffle and track the Chance and Community Chest cards. The cards are stored in lists chest_cards and chance_cards.
def __init__(self):
self.chance = random.shuffle(chance_cards)
self.chest = random.shuffle(chest_cards)
self.chance_count = 0
self.chest_count = 0
def chance(self):
self.chance_count += 1
return self.chance[self.chance_count - 1]
In my main code, I am just running
p = cards()
print (p.chance())
to test my code, but I get TypeError: 'NoneType' object is not callable for the print line.
Any ideas? Or do you need to see more code? TIA
EDIT: Here is the full cards class, if it helps
import random
global chance_count
global chest_count
class cards:
global chest_cards
global chance_cards
chest_cards = (["Go to Jail","Get Out of Jail Free","Advance to Go (Collect $200)",
"Bank error in your favor (Collect $200)","Doctor's fee (Pay $50)",
"From sale of stock you get $50", "Grand Opera Night — Collect $50 from every player",
"Holiday Fund matures (Collect $100)", "Income tax refund (Collect $20)",
"It is your birthday (Collect $10)","Life insurance matures (Collect $100)",
"Pay hospital fees of $100", "Pay school fees of $150", "Receive $25 consultancy fee",
"You are assessed for street repairs – $40 per house – $115 per hotel",
"You have won second prize in a beauty contest (Collect $10)", "You inherit $100"])
chance_cards = (["Go to Jail","Get Out of Jail Free","Advance to Go (Collect $200)",
"Advance to Illinois Ave — If you pass Go, collect $200",
"Advance to St. Charles Place – If you pass Go, collect $200",
"Advance token to nearest Utility. If unowned, you may buy it from the Bank. If owned, throw dice and pay owner a total ten times the amount thrown.",
"Advance token to the nearest Railroad and pay owner twice the rental to which he/she is otherwise entitled. If Railroad is unowned, you may buy it from the Bank.",
"Bank pays you dividend of $50", "Go Back 3 Spaces",
"Make general repairs on all your property – For each house pay $25 –For each hotel $100",
"Pay poor tax of $15","Take a trip to Reading Railroad – If you pass Go, collect $200",
"Take a walk on the Boardwalk – Advance token to Boardwalk",
"You have been elected Chairman of the Board – Pay each player $50",
"Your building and loan matures — Collect $150", "You have won a crossword competition (Collect $100)"])
def __init__(self):
self.chance = random.shuffle(chance_cards)
self.chest = random.shuffle(chest_cards)
self.chance_count = 0
self.chest_count = 0
def chance(self):
self.chance_count += 1
return self.chance[self.chance_count - 1]
cards?self.chance = None