#πŸ”’ Need a small help in blackjack game

37 messages Β· Page 1 of 1 (latest)

blazing bridge
#

https://paste.pythondiscord.com/LIHQ

So I am making a blackjack game, one of the rules was that the card "Ace" can be used as either 1 or 11, in my code I used the ace as 1 but how can I take 11 too?
I only took 1 because I thought taking both will make it very complex but now since I have completed it I want my code to contain all the rules so I am trying to figure it out but wasn't able to figure it, that's where I need help

Also It would really help if you can tell me where I can improve the code and make it better as I am just a beginner.

analog impBOT
#

@blazing bridge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

reef hornet
#

you can input wehter the player wants it to be a one or an 11, input() method

runic bridge
#

Count em as 11's, keep track of how many. If they end up over 21 check how many there were, delete 10 at a time until you're out of aces or under 21.

#

Is likely how I'd do it, only need to update the calculate function

silent spire
#

Count them as 1; then add 10 as long as there is an ace in the hand and adding 10 doesn't bust.

Only one ace can count for 11, because two 11s would already be too much.

round bronze
#

did you manuaally create a tupple of all the cards that is crazy

#

that must have been a lot of work tho

#

you can check wheather the sum of the card is less than a amount where a 11 can fit else you keep it to 1

#

so for example if the sum is 10 or less, ace can be equal to 11 you can define it in the for loop it self creating a local variable and if the sum is greater than 10 then you make ace, to be 1 just by also creating a local variable to do the job

#

sorry it can be from 1 to 11 not 1 or 11 as you stated

grand jackal
#

You should generally avoid global variables

You should avoid string literals

You should use type-hinting

You can use a += b instead of a = a + b

You should use classes/enums

Some function like e.g. your calculate can be massively improved if you incorporate those changes, like e.g. your calculate function could just look like so:

def calculate(cards: list[Card]) -> int:
    total: int = 0
    for card in cards:
        total += card.value
    # or in one line: total: int = sum(card.value for card in cards)

    if total > 21:
        aces_in_hand: int = sum(card.name == CardType.ACE for card in cards)
        # subtract aces from the hand total. I'm not really sure how blackjack works, i.e. if the order of cards matters, etc though
    
    return total
    
blazing bridge
analog impBOT
#

10. Do not copy and paste answers from ChatGPT or similar AI tools.

blazing bridge
grand jackal
#

I mean, it was an answer to your question: "Can you please do the rest for me?"

#

Also it's generally very bad to use LLMs as a learning resource

blazing bridge
#

They are made to assist you

#

And I am using it to assist me

#

Not do my whole work

grand jackal
# blazing bridge They are made to assist you

They are made to assist you, once you already know what you're doing.
Sure, LLMs are great if you already know everything it's telling you and can spot all the places where it makes mistakes and adjust accordingly.
But you right now you are still in the learning phase. You are not experienced enough to know when it makes a mistake, when it's slightly incorrect, or when it follows an inherently flawed approach. If you rely too heavily on LLMs now, you won't learn how to work without them and you will pick up a lot of bad habits in the process.

#

I like to quote this conclusion:

ChatGPT is a Comfort Trap Students perceived ChatGPT as significantly more helpful and easier to use, yet these preferences aligned with greater reductions in learning-related cognitive processing and did not lead to better learning outcomes. This perception-reality gap reveals how student preferences may mislead pedagogical decisions.
[...]
This inverse relationship between student preferences and pedagogical outcomes aligns with existing literature showing that students’ perceptions of learning can be inversely related to actual learning outcomes (Deslauriers et al., 2019), that satisfaction ratings have near-zero correlation with objective learning measures (Uttl et al., 2017), and that learners often prefer easier but less effective methods (Yan et al., 2016).
Source

blazing bridge
#

Shit is deep

#

Didn't expect it to be

#

My bad

grand jackal
#

no worries. It's very common

blazing bridge
#

But what should I do when I get stuck like ppl will find me annoying for asking simple questions continuously

grand jackal
# blazing bridge But what should I do when I get stuck like ppl will find me annoying for asking ...

Most of the time, the kind of problems you have are problems that many people have experienced before you already, and there's like a 99% chance it is answered on StackOverflow or some other similar platform, sometimes it's an obscure blog or article. Avoid Geeks4Geeks and W3School though, they are very bad.
If it isn't (or you just can't find anything in that regard) then it's also perfectly fine to ask for help here.

blazing bridge
round bronze
#

well i also use LLMs but i usually know what i am doing i guess

blazing bridge
#

!close

analog impBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.