我正在做一个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()
注:
货币变量类似于500
或200
问题:
[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
正如错误所说,不能将字符串和整数连接在一起。看起来您的文件正在读取字符串,因此您需要将其转换为如下
int(money)
所示的整数才能执行数学运算相关问题 更多 >
编程相关推荐