My first-year teaching AP CS. Below is the code the student is using. The project is blackjack.
creates a card object that has three characteristics- it’s name, it’s suit, and it’s point value in the game. it also creates methods that allow the access of the characteristics of the card so it can be used in the game
class Card:
def init(self, s, n, v):
self.name = n
self.suit = s
self.val = v
def return_name(self):
return self.name
def return_suit(self):
return self.suit
def return_val(self):
return self.val
def __str__(self):
return self.name + self.suit
makes a deck of 52 cards, 13 cards 2-A, for each suit, and assigns each card to a random spot in the deck arraylist to make sure the cards are shuffled
def make_deck():
global deck
suit = “”
deck =
spot = 0
for i in range(3, 7):
if i == 3:
suit = “hearts”
if i == 4:
suit = “diamonds”
if i == 5:
suit = “clubs”
if i == 6:
suit = “spades”
for num in range(1, 14):
if num == 1:
deck.append(Card(str(suit), “Ace”, 11))
elif num == 11:
deck.append(Card(str(suit), “Jack”, 10))
elif num == 12:
deck.append(Card(str(suit), “Queen”, 10))
elif num == 13:
deck.append(Card(str(suit), “King”, 10))
else:
deck.append(Card(str(suit), str(num), num))
spot += 1