-2

I am trying to write out a program that tells how much damage someone causes to an object and i want to also print out how much damage it delt, but even after looking what I found doesn't seem to work. Here is the code

damage = random.randint(1,3)
print ("You delt %"+damage+"% damage")

If any one knows why it isn't working I would be very thankful.

4
  • What are the {} doing there? Commented Feb 20, 2016 at 23:33
  • I am very bad at using this website... But I'm learning Commented Feb 20, 2016 at 23:34
  • 1
    @cryce, you cannot add a string and an int, use print("You delt {}% damage".format(damage)) Commented Feb 20, 2016 at 23:34
  • Fixed that for you. Please always include the full error message. "Something does not work" is not helpful. Although in this case, it is obvious that you'll have to use str(damage) in your call to print. Commented Feb 20, 2016 at 23:35

1 Answer 1

2
print ("You delt %" + str(damage) + "% damage")
You delt %1% damage

better way:

print ("You delt %{}% damage".format(damage))
Sign up to request clarification or add additional context in comments.

5 Comments

What's with the %?
Ah, thank you, it works perfectly now
I had found another supposed way to print integers as strings but it seems I misunderstood
@e0k, just using the question's text.
@cryce, you means print ("You delt %d damage" % damage) ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.