-1

I'm making a text based world domination game using python, And for the currency in the game I want to put it in a print statement, so I converted the currency from int to str, and know if I try to subtract from it, it gives me a error.

So I tried, to convert the int into str by for example: money = str(1000) and then do: money -=100 then print("you have" + money + "left"), but I got a error when running it.

Rishi
  • 1
  • 1
  • If it is helpful to know, I'm using Google Collab to run my code. – Rishi Feb 19 '23 at 15:52
  • 3
    So just _don't_ convert to a string I guess?! – tkausl Feb 19 '23 at 15:53
  • Welcome to Stack Overflow. "And for the currency in the game I want to put it in a print statement, so I converted the currency from int to str, and know if I try to subtract from it, it gives me a error." Then **don't do that**. Do the math first, and **then** use **completely different technique** to deal with the fact that you "want to put it in a print statement". Please see the linked duplicates. Numbers are for math. Strings are not for math. – Karl Knechtel Feb 19 '23 at 15:54
  • You can convert to string on demand: `print(str(money))`. `money` itself never needs to be a `str`. – chepner Feb 19 '23 at 17:02

1 Answers1

-1

I think you can do int(money) to do math again. But, why did you convert money into a string lol. You just should keep it in int, and to print the value see : https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/

money = 1000
money = str(money)

int_money = int(money)
int_money -= 1000

print(f"You have {int_money} left)