Question

# Write a program that takes user input describing a playing card in the following shorthand notation: A Ace 2 ... 10 Card values J Jack Q Queen K King D Diamonds H Hearts S Spades C Clubs Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades

Solution

Verified
Step 1
1 of 2
card = input("Enter a card notation: ")

# card is string with length 2
# or 3 (only if the value is 10)

# if length is 2
# first character is value
if len(card) == 2:
value = card[0]
# and second character is sign of the card
sign = card[1]
# and if length is 3
# first two characters are value
else:
value = card[:2]
# and third is sign
sign = card[2]

if value.upper() == "A":
output = "Ace "
elif value.upper() == "J":
output = "Jack "
elif value.upper() == "Q":
output = "Queen "
elif value.upper() == "K":
output = "King "
# card value is 2, 3, ..., or 10
else:
output = value + " "

# concatenate the sign of card
if sign.upper() == "D":
output += "of Diamonds"
elif sign.upper() == "H":
output += "of Hearts"
elif sign.upper() == "S":
else:
output += "of Clubs"

# print an output
print(output)


## Recommended textbook solutions

#### Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (8 more)David A. Patterson, John L. Hennessy
220 solutions

#### Fundamentals of Database Systems

7th EditionISBN: 9780133970777 (1 more)Ramez Elmasri, Shamkant B. Navathe
687 solutions

#### Introduction to Algorithms

3rd EditionISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions

#### Python for Everyone

2nd EditionISBN: 9781119056553 (3 more)Cay S. Horstmann, Rance D. Necaise
730 solutions