So, I am making a test SCII adventure game and when i need to print out the enemy HP it tells me I can’t print int values with str values.
Code:
enemy_hp=73
print("Enemy HP: " + enemy_hp)
Result:
TypeError: can only concatenate str (not "int") to str
Wanted result:
Enemy HP: 73
Can someone help me out pls.
>Solution :
This happens because you are concatenating int and strings when printing out
You can solve this in various ways
- using a format string
print(f'Enemy HP: {enemy_hp}')
- converting int to str
print('Enemy HP: '+ str(enemy_hp))