gpt4 book ai didi

Python - 不支持的操作数类型 - : 'int' and 'str'

转载 作者:太空宇宙 更新时间:2023-11-04 10:14:12 25 4
gpt4 key购买 nike

所以我正在开发一个小轮盘赌程序,当我尝试获取/添加到用户余额时,它会出现标题为错误的错误,是什么让程序这样做以及如何解决它?

import random
import time

balance = 100

outcome = random.randint(0,17)
if outcome == 0:
color = "GREEN"
elif outcome <=7:
color = "RED"
else:
color = "BLACK"

print("Current Balance: $"+str(balance))
colorChoice = input("Place your bet by typing either: RED, GREEN or BLACK\n")
colorChoice = colorChoice.upper()
betAmount = input("How much would you like to bet?\n")
if int(betAmount) > balance:
print("Insufficient Funds")
else:
print("** ROLLING **")
time.sleep(2.5)
print("The color landed on: " + color)
if colorChoice == color and color == "GREEN":
print("Win! Your balance has been adjusted!\nYou selected: " + colorChoice + " and the spinner landed on: " + color)
greenLand = betAmount * 14
balance = balance + greenLand
elif colorChoice == color and color == "RED":
print("Win! Your balance has been adjusted!\nYou selected: " + colorChoice + " and the spinner landed on: " + color)
balance = balance + betAmount
elif colorChoice == color and color == "BLACK":
print("Win! Your balance has been adjusted!\nYou selected: " + colorChoice + " and the spinner landed on: " + color)
balance = balance + betAmount
elif colorChoice != color and color == "GREEN":
print("Loss! Your balance has been adjusted!\nYou selected: " + colorChoice + " and the spinner landed on: " + color)
balance = balance - betAmount
elif colorChoice != color and color == "RED":
print("Loss! Your balance has been adjusted!\nYou selected: " + colorChoice + " and the spinner landed on: " + color)
balance = balance - betAmount
elif colorChoice != color and color == "BLACK":
print("Loss! Your balance has been adjusted!\nYou selected: " + colorChoice + " and the spinner landed on: " + color)
balance = balance - betAmount
print("New Balance: $" + str(balance))

为了不让这篇文章被否决,我想重申,当我尝试在底部的 if/elif 语句中操作 balance 变量时,我的问题出现了!

最佳答案

您的 betAmount 应声明为 int(input("How much would you like to bet?\n")) 以使其成为整数。并如评论所述,使整数与整数匹配。算术上。

关于Python - 不支持的操作数类型 - : 'int' and 'str' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36380782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com