-1

Very early stages of learning Python, and trying to complete 100 days of code challenge. Am building a crude blackjack game, but am stuck on what I am sure is probably a very simple fix that I don't recognise!

This is my code so far:

import random

cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]

players = ["player", "dealer"]

players_hands = {}
players_scores = {}


for player in players:

    cards = random.choices(cards, k = 2)
    players_hands[player] = cards
    players_scores[player] = sum(cards)
    
print(players_hands["player"])

print(players_scores["player"])

print(f"Your cards: {players_hands["player"]}, current score: {players_scores["player"]}")

print(f"Dealer's first card: {players_hands["dealer"][0]}")**

I want to print the f-string version rather than the basic print statement, but keep getting a syntax error and don't know what I've done wrong.

khelwood
  • 55,782
  • 14
  • 81
  • 108

1 Answers1

2

You should check that you are using at least Python 3.6, which f-strings were introduced in, but also...

You are using double quotes to access the dictionary, which is conflicting with using double quotes for the string. Try changing to either

print(f"Dealer's first card: {players_hands['dealer'][0]}")

or

print(f'Dealer\'s first card: {players_hands["dealer"][0]}')
Kemp
  • 3,467
  • 1
  • 18
  • 27