I just started learning python and then this card game came out and I had no idea what to do. Basically, I need to create a for-loop inside of which I ask the user for card:. Most importantly, I need to define a function outside of main(), like def ppcard( card ):, and prints out the "pretty-print" version of that card. If a user put card: 4h, the output should be 4 of Spade. So that's where I got confused and I tried lots of times but I don't know how I can do the pretty print. I don't know how to match the values in deck like the 's' in '2s' to 'Spade'.
Asked
Active
Viewed 313 times
0
-
I don't follow what you're asking; "So that's where I got confused and I tried lots of times but I don't know how I can do the pretty print. I don't know how to match the values in deck like the 's' in '2s' to 'Spade'.". What is the question ; pretty printing or matching strings? – roganjosh Sep 27 '19 at 12:48
-
pretty printing. like how can I print '2 of Spade' from '2s' – xianyu Sep 27 '19 at 12:58
1 Answers
2
You can use the respective letter in card
as keys for the ranks
and suits
dicts:
def ppcard(card):
print(ranks[card[0]], 'of', suits[card[1]])
Also note that you're missing quotes around the strings for the keys of the suits
dict:
suits = {"s": "Spades", "h": "Hearts", "d": "Diamonds", "c": "Clubs"}

blhsing
- 91,368
- 6
- 71
- 106
-
1Also, you have to correct the rank dictionary (to use quotes around the strings) – Lev Leontev Sep 27 '19 at 12:51
-
Thanks!!! But there is an error: ppcard() missing 1 required positional argument: 'card' Do i need to do anything with the position of main() and ppcard()? – xianyu Sep 27 '19 at 13:01
-
Yes you would have to call `ppcard` with argument, such as `ppcard('2s')`. – blhsing Sep 27 '19 at 13:16