所以我正在开发一个小小的轮盘程序,当我尝试接受/添加用户平衡时,它会出现标题错误,程序执行此操作的原因以及如何修复它?
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变量时发生我的问题!
答案 0 :(得分:4)
您的betAmount应声明为int(input("How much would you like to bet?\n"))
以使其成为整数。并且如评论所述,使整数与整数匹配。算术。