2

I am trying to print ascii playing cards for a poker game but it's not working as planned.

I tried printing playing cards using unicode for my poker program in python but when I use the unicode the console comes up with this error: "SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape" and when I copy and paste the ascii from the website (which I'd prefer not to do) it only prints cards with a question mark on them

here is my code:

backOfCard = '\u+1f0a0'
print(backOfCard)
wildflower
  • 19
  • 3

1 Answers1

3

The syntax for unicode escapes in Python is \uxxxx for 16-bit values, and \Uxxxxxxxx for 32-bit values, so you want \U0001f0a0.

(Or '\N{playing card back}'.)

Ture Pålsson
  • 6,088
  • 2
  • 12
  • 15
  • Awesome, the codes working but I'm still just getting them as cards with question marks. I assume I'd have to download something. – wildflower Jan 07 '23 at 17:53
  • 2
    If you get question marks, that probably means that you are using a font that does not have that character. – Ture Pålsson Jan 07 '23 at 18:08
  • I don't follow, I am using default windows font – wildflower Jan 07 '23 at 18:13
  • 1
    @wildflower - where are you displaying the output that you are seeing the `?` output. It may be using a font that doesn't support any Unicode. Another option that isn't included in this answer is to simply put the Unicode characters directly into your script such as `` – nigh_anxiety Jan 07 '23 at 18:42
  • @nigh_anxiety yip i tried that too and it still pops up with the same and it only does this in my console, other text seems fine. My best best bet is creating my own cards with ascii as the suit symbols work fine but the card symbols would be much more efficient. – wildflower Jan 07 '23 at 21:49
  • @wildflower What are you using for your console, and on which OS? You may just need to look for info on how to update that to use Unicode, if possible. Otherwise run your code in an IDE where the terminal programs support Unicode, such as VSCode. – nigh_anxiety Jan 07 '23 at 23:21