fork download
  1. #
  2. # Write a program that takes user input describing a
  3. # playing card in the following shorthand notation:
  4. # A Ace D Diamonds
  5. # 2...10 Card values H Hearts
  6. # J Jack S Spades
  7. # Q Queen C Clubs
  8. # K King
  9. #
  10. # Your Program should print the full description of the card.For example,
  11. #
  12. # Enter the card notation: QS
  13. # Queen of Spades
  14. #
  15.  
  16. cardNotation = raw_input("Enter card notation: ")
  17.  
  18. # Create a dict for values
  19.  
  20. cardColors = {"D": "Diamonds",
  21. "H": "Hearts",
  22. "S": "Spades",
  23. "C": "Clubs"}
  24.  
  25. cardNumberValues = {"A": "Ace",
  26. "J": "Jack",
  27. "Q": "Queen",
  28. "K": "King",
  29. "2": "Two",
  30. "3": "Three",
  31. "4": "Four",
  32. "5": "Five",
  33. "6": "Six",
  34. "7": "Seven",
  35. "8": "Eight",
  36. "9": "Nine",
  37. "10": "Ten"}
  38.  
  39. # Handle cases when 10 comes in input
  40. if len(cardNotation) == 3:
  41.  
  42. number = cardNotation[0:2]
  43. color = cardNotation[2:0]
  44. print cardNumberValues[number] + " of " + cardColors[color]
  45.  
  46. elif len(cardNotation) == 2:
  47.  
  48. number = cardNotation[:1]
  49. color = cardNotation[1:]
  50. print cardNumberValues.get(number) + " of " + cardColors.get(color)
  51.  
  52. else:
  53. print "INVALID VALUE"
  54.  
Success #stdin #stdout 0.01s 23296KB
stdin
QS
stdout
Enter card notation: Queen of Spades