我正在写一个赌场骰子游戏,要求用户输入赌注和骰子号码。骰子编号的结果将从余额中扣除下注或将投注* 6添加到余额中。当用户猜错时,从天平中扣除正确的值。
剩余的余额为490,并且在下注5之后赢得下注,新余额为556045.这显然应该是520。
为什么新余额为556045?
我的代码和输出一起在下面
import random
print("Welcome to the casino")
UserName = input("Please enter your name: ")
print("Thanks for playing " + UserName + "! We wish you the best of luck!")
balanceRemaining = 500
while balanceRemaining != 0:
RandomNumber = random.randint(1, 6)
Wager = input("Please enter a wager: ")
UserNumber = input("Enter a number: ")
print("Dice number was " + str(RandomNumber))
if int(UserNumber) != RandomNumber:
balanceRemaining = balanceRemaining - int(Wager)
print("Your Balance is now: " + str(balanceRemaining))
else:
Winnings = int(Wager * 6)
balanceRemaining = int(Winnings) + int(balanceRemaining)
print("Your Balance is now: " + str(balanceRemaining))
产量
Please enter a wager: 5
Enter a number: 5
Dice number was 1
Your Balance is now: 495
Please enter a wager: 5
Enter a number: 5
Dice number was 6
Your Balance is now: 490
Please enter a wager: 5
Enter a number: 5
Dice number was 5
Your Balance is now: 556045