spending 4 days on a blackjack game that takes 4 seconds to play
Too real :)
I took a look at your code, congrats on getting it working. One point I saw is that you've hardcoded your card logic to work with exactly 6 decks. Can you think of a way to generalize this to n decks? That way, the user can choose, or you can use an appropriate amount for the number of players. You can do this just using functions, but this might be an opportunity to get practice defining your own classes, too.
I would also recommend wrapping up your running logic, and using the if __name__ == "__main__" idiom. See this post for an explanation of what that does and why it's a good idea.
Definitely don't take this as bashing your code - you succeeded here! Your program does the thing. First of many.
Hey, I'm not expecting to spend a whole lot more time on this exercise, however I can't help thinking about ways to improve it...
What if I used a class to handle the players? (I'm at my actual day job right now, so I can't look at it) The problem I see is how to handle instantiating some random amount of players? If you look at the code I have now I'm handling it with dictionaries, which I think is a good method, however could I do the same type of thing for classes?
Definitely! I think that's a good idea. You can have an overarching Game class that maintains a list of players and the list of cards, and ask for how many players to create in the constructor. Then, each player can be a Player instance, you can have a CardDeck, and a Card...I think classes and objects are really useful for organizing your code as it gets bigger. You can keep most of the same actual logic, it just provides a convenient, readable structure.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice work!
Too real :)
I took a look at your code, congrats on getting it working. One point I saw is that you've hardcoded your card logic to work with exactly 6 decks. Can you think of a way to generalize this to
n
decks? That way, the user can choose, or you can use an appropriate amount for the number of players. You can do this just using functions, but this might be an opportunity to get practice defining your own classes, too.I would also recommend wrapping up your running logic, and using the
if __name__ == "__main__"
idiom. See this post for an explanation of what that does and why it's a good idea.Definitely don't take this as bashing your code - you succeeded here! Your program does the thing. First of many.
Oh no, I really appreciate the feedback! It's nice to get the perspective of someone who currently does this stuff for a living.
I'm checking that stackoverflow out now.
I've only been a "real" programmer for a few months ;). People who write programs that work are real programmers.
Hey, I'm not expecting to spend a whole lot more time on this exercise, however I can't help thinking about ways to improve it...
What if I used a class to handle the players? (I'm at my actual day job right now, so I can't look at it) The problem I see is how to handle instantiating some random amount of players? If you look at the code I have now I'm handling it with dictionaries, which I think is a good method, however could I do the same type of thing for classes?
Definitely! I think that's a good idea. You can have an overarching
Game
class that maintains a list of players and the list of cards, and ask for how many players to create in the constructor. Then, each player can be aPlayer
instance, you can have aCardDeck
, and aCard
...I think classes and objects are really useful for organizing your code as it gets bigger. You can keep most of the same actual logic, it just provides a convenient, readable structure.