I'm trying to create a python cards game (a Brazilian cards game). But when I try to print some values (the cards played) it returns the following error:

Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
play()
File "C:\Documents and Settings\Terminal\Desktop\Truco.py", line 71, in play
print "You played %a. The computer played %b and %c" % (player_card1, computer_card1, computer_card2)
ValueError: unsupported format character 'a' (0x61) at index 12

player_card1, computer_card1, computer_card2 are numbers from a list...

example:

from random import choice as rc
cards = [1, 2, ...]

player = []

player.append(rc(cards))
player.append(rc(cards))
player.append(rc(cards))

player_card1 = player[0]

Use lowercase for your string formatting expression.

>>> print 'Hi this is a %s' % 'test'
Hi this is a test
>>> print 'Hi this is a %S' % 'test'
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ValueError: unsupported format character 'S' (0x53) at index 14
>>>

I did so.

print "You played %a. The computer played %b and %c" % (player_card1, computer_card1, computer_card2)

What you want with %a format. You should have %s for strings, %f for floats, %i for integers %x for hexadecimal.

I never heard about %a , %b or %c formatting.

Try.
print "You played %s. The computer played %s and %s" % (player_card1, computer_card1, computer_card2)

You can not use a% b% c%
http://docs.python.org/library/stdtypes.html#string-formatting-operations

Most commen formatting expression.
%s == String (converts any Python object using str()).
%d == Signed integer decimal
%f == Floating point decimal format.

tonyjv and snippsat:

I've never heard about that. I'm just beginning with python coding, heh
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.