Python printing text after printing a variables

96,025

Solution 1

Just include the hitpoints:

print('The enemey gets hit for %d hitpoints' % damage)

The formatting operator % is very powerful, have a look at all the placeholder options. It is, however, intended to be phased out in favor of str.format:

print('The enemey gets hit for {} hitpoints'.format(damage))

Alternatively, you can convert the value of damage to a string, and concatenate strings with +:

print('The enemy gets hit for ' + str(damage) + ' hitpoints')

Solution 2

Looks much nicer this way. ;0)

damage = 10
print(f'The enemey gets hit for {damage} hitpoints')

(for python 3.6 & above)

Solution 3

Just add hitpoints to your string:

print('the enemy gets mutilated for %d hitpoints!' % damage)
Share:
96,025
Admin
Author by

Admin

Updated on July 05, 2022

Comments

  • Admin
    Admin almost 2 years

    So I wanna print some text after i print my variables like this:

    print('Blablabla' var ' blablabla')
    

    Right now it looks like this:

     print('The enemey gets hit for %d' % damage)
    

    I wanna print the word "Hitpoints" after I've printed the damage variable.