0
def deal_card():

    cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
    card = random.choice(cards)
    return card

user_cards = []

computer_cards = [] 

for _ in range(2):

    user_cards.append(deal_card())
    computer_cards.append(deal_card())

draw_another_card = input("Type 'y' to get another card, type 'n' to pass : ")

if draw_another_card == "y":

    new_user_cards = user_cards.append(deal_card())
    new_computer_cards = computer_cards.append(deal_card())
    print(new_user_cards)

when I print new_user_cards, it shows none. I don't understand why, I googled a lot but couldn't get any answers.

The random function is from replit.

I would really like to what is going wrong in the above code!

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Shaivik7
  • 13
  • 3

1 Answers1

0

In addition to the comments of @ThierryLathuille and @Sujay.

If you want the new_user_card and new_computer_card values, you can:

Replace:

    new_user_cards = user_cards.append(deal_card())
    new_computer_cards = computer_cards.append(deal_card())

By:

    new_user_card = deal_card()  # without plural because there is only one
    user_cards.append(new_user_card)
    new_computer_card = deal_card()  # without plural because there is only one
    computer_cards.append(new_computer_card)

Or:

    user_cards.append(deal_card())
    new_user_card = user_cards[-1]  # last item of the list
    computer_cards.append(deal_card())
    new_computer_card = computer_cards[-1]  # last item of the list
Corralien
  • 109,409
  • 8
  • 28
  • 52
  • Hey Corralien, it worked perfectly, Thank you very much and I also understood where I was going wrong with the append function! – Shaivik7 Jul 25 '21 at 13:01