打印数字时有问题

2024-06-02 05:32:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个coinflip游戏,它可以将你输入的值添加到你的余额中

早期版本的代码片段:

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]eads或[T]ails 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

Tags: 代码you游戏inputelse余额intprint