Having issues getting this to print both the card number and suite in python. Th
ID: 3731741 • Letter: H
Question
Having issues getting this to print both the card number and suite in python. The card number seems to be working fine but not the suite what am I missing?
def main():
# variable
cardNotation = input("Enter card notation: ")
if len(cardNotation) is 2:
if cardNotation[0] is "K":
print("King of ",end="")
elif cardNotation[0] is "Q":
print("Queen of ",end="")
elif cardNotation[0] is "J":
print("Jack of ",end="")
elif cardNotation[0] is "A":
print("Ace of ",end="")
elif cardNotation[0].isdigit():
print(cardNotation[0],"of ",end="")
if cardNotation[0] is "D":
print("Diamonds")
elif cardNotation[0] is "H":
print("Heart")
elif cardNotation[0] is "S":
print("Spade")
elif cardNotation[0] is "C":
print("Club")
if len(cardNotation) is 3:
if cardNotation[0] is "1" and cardNotation[1] is "1":
print("10 of ",end="")
if cardNotation[2] is "D":
print("Diamonds")
elif cardNotation[2] is "H":
print("Heart")
elif cardNotation[2] is "S":
print("Spade")
elif cardNotation[2] is "C":
print("Club")
main()
Explanation / Answer
def main():
# variable
cardNotation = input("Enter card notation: ")
if len(cardNotation) is 2:
if cardNotation[0] is "K":
print("King of ",end="")
elif cardNotation[0] is "Q":
print("Queen of ",end="")
elif cardNotation[0] is "J":
print("Jack of ",end="")
elif cardNotation[0] is "A":
print("Ace of ",end="")
elif cardNotation[0].isdigit():
print(cardNotation[0],"of ",end="")
if cardNotation[1] is "D":
print("Diamonds")
elif cardNotation[1] is "H":
print("Heart")
elif cardNotation[1] is "S":
print("Spade")
elif cardNotation[1] is "C":
print("Club")
if len(cardNotation) is 3:
if cardNotation[0] is "1" and cardNotation[1] is "0":
print("10 of ",end="")
if cardNotation[2] is "D":
print("Diamonds")
elif cardNotation[2] is "H":
print("Heart")
elif cardNotation[2] is "S":
print("Spade")
elif cardNotation[2] is "C":
print("Club")
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.