Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How To Print int Values

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

  1. using a format string
print(f'Enemy HP: {enemy_hp}')
  1. converting int to str
print('Enemy HP: '+ str(enemy_hp))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading