Search code examples
pythonstringrandomintcoin-flipping

Having issues with numbers being printed


I'm working on a coinflip game which adds your inputed value to your balance

Snippets of code from earlier:

deposit = input("Enter how much to deposit")

money = file1.read()

resultmonecoin = int(money)-int(deposit)

Main code that test if you got Tails right

elif flipresults == "Tails":
                    print("You flip the coin")
                    time.sleep(2)
                    print("It's tails")
                    if HORT.upper() == "T" or "t":
                        wincoin = int(deposit)*2
                        print("You won",wincoin)
                        howmuchwin = wincoin+money
                        print("Total:",int(howmuchwin))
                    else:
                        print("You lost that one. You now have",resultmonecoin)
                        game()
                else:
                    print("This input wasn't understood!")
                    flip()

Note: money variable is something like 500 or 200

Issue:

[H]eads or [T]ails T

You flip the coin

It's tails

You won 468

Traceback (most recent call last):
File "C:\Users\yeet\Desktop\Casino.py", line 40, in flip
    howmuchwin = wincoin+money
TypeError: unsupported operand type(s) for +: 'int' and 'str

Solution

  • As the error says you can't concatenate a string and an integer together. Looks like your file is reading in a string so you need to cast it as an integer like this int(money) to be able to perform maths operations