打印数字时出现问题

时间:2018-10-16 17:45:14

标签: python string random int coin-flipping

我正在研究一款硬币翻转游戏,该游戏可以将您输入的值添加到您的余额中

以前的代码片段:

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

money = file1.read()

resultmonecoin = int(money)-int(deposit)

测试尾部是否正确的主要代码

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()

注意: 货币变量类似于500200

问题:

[H]个或[T]个T

您掷硬币

是尾巴

您赢了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

1 个答案:

答案 0 :(得分:1)

如错误所示,您不能将字符串和整数连接在一起。看来您的文件正在读取字符串,因此您需要将其转换为整数,例如int(money)才能执行数学运算