Related questions with answers
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
VerifiedAnswered 3 months ago
Answered 3 months ago
Step 1
1 of 2card = 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":
output += "of Spades"
else:
output += "of Clubs"
# print an output
print(output)
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th Edition•ISBN: 9780124077263 (8 more)David A. Patterson, John L. Hennessy220 solutions

Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777 (1 more)Ramez Elmasri, Shamkant B. Navathe687 solutions

Introduction to Algorithms
3rd Edition•ISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen726 solutions

Python for Everyone
2nd Edition•ISBN: 9781119056553 (3 more)Cay S. Horstmann, Rance D. Necaise730 solutions
More related questions
1/2
1/3