Files
stuff/activity3-transfer.py
Maxwell Jeffress 3fdb90a652 Stuff
2026-02-20 11:42:22 +11:00

65 lines
1.5 KiB
Python

# Created by Maxwell Jeffress on 17/02/2026
# Simulates a game of Blackjack
import random
cards = [card for card in range(2, 11) for _ in range(4)]
def card_string(card: int) -> str:
match card:
case 11:
return "Jack"
case 12:
return "Queen"
case 13:
return "King"
case 14:
return "Ace"
case _:
return str(card)
# Create the card order
random.shuffle(cards)
def deal_card(cards: [int]) -> int:
return cards.pop()
print(cards)
you = 0
dealer = 0
card1 = deal_card(cards)
card2 = deal_card(cards)
you += card1 + card2
print("You got dealt", card_string(card1), "and", card_string(card2), "for a total of", you)
dealer += deal_card(cards) + deal_card(cards)
print("Shh dont tell them but the dealer has", dealer)
dealerWon = False
while True:
hors = input("Hit or stand? ")
if hors.lower() in ["h", "hi", "hit", "hit me"]:
print("Hitting")
card = deal_card(cards)
you += card
print("You got dealt", card_string(card), "for a total of", you)
if (you > 21):
print("Bust!")
dealerWon = True
break
elif hors.lower() in ["s", "st", "sta", "stan", "stand", "stand up"]:
print("Standing")
break
else:
print("That's not valid!")
continue
if not dealerWon:
print("Dealing the dealer")