0

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
asked Oct 22, 2015 at 1:19
3
  • The error message included line information. Please include it. Commented Oct 22, 2015 at 1:22
  • You don't need the parens around your strings and you need %s not just % Commented Oct 22, 2015 at 1:24
  • 1
    That's the fifth line in the code, "print ("A % has appeared!") % ('ename')" Commented Oct 22, 2015 at 1:24

2 Answers 2

1
("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
Sign up to request clarification or add additional context in comments.

1 Comment

Right as I saw this, I remembered it. I've made stuff like this before, thanks :)
0

("A % has appeared!") % ('ename') should be

print("A %s has appeared!" % 'ename')

answered Oct 22, 2015 at 2:08

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.