Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I have a question for Python 3.6.4. I have to make a class Card. Inside o

ID: 3711280 • Letter: H

Question

Hello, I have a question for Python 3.6.4.

I have to make a class Card. Inside of the class I have to have a function that gets the suit(Hearts, Diamond, Spades, Clubs), one that gets the value(2-10 are face value, J-K = 10, Ace = 11), and one that gets the rank( returns Ace, King, Queen, Jack, 2-10) of a 52 card deck. I'm not allowed to use loops or use the words 'Ace', 'King', 'Queen', 'Jack', 'Hearts', 'Spades', 'Diamonds', and 'Clubs' more than once. I've tried a dictionary for Ace, 2-10, J-K, as well as a dicitonary for the suits. The input has to be a number 1 - 52, so, Spades = 1 - 13, Hearts = 14 - 26, Diamonds = 27 - 39, Clubs = 40 - 52.

Any ideas?

Explanation / Answer

class Card(object):
def __init__(self):
self.rank = ["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10" "Jack", "Queen", "King"]
self.suits = ["Spades", "Hearts", "Diamond", "Clubs"]
def get_suit(self, num):
suit = 0
if num <= 13:
suit = 0
elif num <= 26:
suit = 1
elif num <= 39:
suit = 2
else:
suit = 3
return self.suits[suit]
def get_rank(self, num):
rank = (num-1) % 13
return self.rank[rank]
def get_face(self, num):
rank = (num-1) % 13
rank = rank +1
if rank >= 2 and rank <= 10:
return rank
elif rank == 1:
return 11
else:
return 10

# copy pastable code link: https://paste.ee/p/FNNS7

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote