You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
I am trying to write my first python project blackjack. I was advised to write the program with each class and its methods in a different file so that the code would be more manageable. I divided my code up into smaller files and used import statements.
When I run my code I get the following error message. Chips.place_bet() missing 1 required positional argument. โselfโ. I thought self was, pardon the pun, self explanatory. I do not need to put a value for self. I am wondering if this is an import issue.
I am trying to get my place_bet function to activate so that I can ask the user to input the number of chips for a bet. Can anyone advise me on how to do this?
I have used hastebin to copy my code into a manageable link as I do not know how to upload files into stack overflow. I have also combined all of the code together in one link here separated by the file name.
https://paste.pythondiscord.com/niduheruso
Does anyone have advice for a rookie?
I have tried calling the function and have gotten an error. Nothing else to be honest.
Hey strikeouts27,
There are a few errors in this code. Since you moved display_chips
under the Chip
class, it needs self
as an argument:
def display_chips(self, player, dealer):
print(f'player chips: ${player.chips.balance}')
print(f'dealer chips: ${dealer.chips.balance}')
# Displays player and dealer chip count
The same for display_hand_two
.
def display_hand_two(self, player, dealer):
# Displays player and dealer hand
print(
f'players Hand: {player.hand.display_hand()} --> total {player.total}')
print(
f'dealer Hand: {dealer.hand.display_hand()} --> total {dealer.total}')
In your current code, you have two main()
functions - get rid of one. You also noticed you have two display_hand
functions; One takes two arguments and the other takes none. Decide which one you want top use on line 233, and Line 247, 266, 269, 273, and 276.
1 Like
I have a couple of questions.
What does if__name__==โmainโ:
main() do?
Is this where I place my gameplay code?
When you say that you get more functionality using len and get item what do you mean by more functionality?
In blackjack.py I print statements welcoming the player to the game. I want the user to input their name and that name be used throughout the code. Is there a way to create the player or instantiate the player based on the name given? Or is it far simpler to just call the user the user and create a player object named user?
I am starting to think that I need to take the github course in codecademy and pass it so I can upload code and document changes.
most up to date code is: Hastebin
I wanted to thank you again for helping me
-strikeouts27/philipandrewstribling