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

Card Naming Write a function called card _namer that takes two single character

ID: 3586744 • Letter: C

Question

Card Naming Write a function called card _namer that takes two single character strings, representing the value and suit of a card following the shorthand below, and returns the full name of the card. Some sneaky cheaters have been trying to slip in fake cards, like the 9 of triangles. So if the suit input isn't one of the recognized inputs the function should return 'CHEATER! '1. You may assume that value will be always be a valid input. Input Value Input Suit ce Diamonds Clubs Hearts Spades 10 Jack ueen King HINT: There is an easy and a hard way to go about writing this function. If you're doing it properly, you should only need two if statements and no more than 25 lines of code An example output of the function would be >>> card_namer ('Q', 'D' 'Queen of Diamonds' >>> card_namer ('9', 'S '9 of Spades >>> card namer ('8', 'T' CHEATER!

Explanation / Answer

This can be done in only 1 if statement as follow:

def card_namer(value, suit):

valid_faces = {'2': '2', '3': '3','4': '4','5': '5','6': '6','7': '7','8': '8','9': '9','A': 'Ace','T': '10','J': 'Jack','Q': 'Queen','K': 'King'}
valid_suits = {'D': ' of Diamonds', 'S': 'of Spades', 'C': 'of Clubs', 'H': 'of Hearts'}
if not value in valid_faces.keys() and suit in valid_suits.keys():
return 'Cheater'
else:
return valid_faces[value] + valid_suits[suit]
  

print (card_namer('J','D'))