I have tried over and over again in order to get my code to work, but it just hasn't.
ename = "Blue Slime"
ehp = 5
edf = 0
eatk = 1
print ("A % has appeared!") % ('ename')
print ("Enemy Stats:")
print ("HP = %") % ('ehp')
print ("DF = %") % ('edf')
print ("ATK = %") % ('eatk')
When I run it, the program says
ValueError: unsupported format character 'a' (0x61) at index 5
I can't figure out what the issue is, and I would like some help with what I should change.
idjaw
26.8k10 gold badges68 silver badges84 bronze badges
2 Answers 2
("A % has appeared!") % ('ename')
should be
("A %s has appeared!") % ('ename')
i.e. you need a format specifier s after %. Read up on string formatting again.
answered Oct 22, 2015 at 1:23
Alex Hall
36.2k5 gold badges63 silver badges98 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Rogue Of Time
Right as I saw this, I remembered it. I've made stuff like this before, thanks :)
("A % has appeared!") % ('ename') should be
print("A %s has appeared!" % 'ename')
Comments
lang-py
%snot just %