我一直在做一个赌博游戏,你必须猜一个数字来赚取你下注的金额,但是我希望游戏永远持续下去,只要“玩家”仍然有钱,我怎么做
这是我到目前为止的代码
import random
print("Welcome to gambling simulator the objective is to get as much money as possible without losing it all you start with 500 dollars, GOOD LUCK!")
rngone = int(input("Where do you want your range to be? >>> "))
tries = int(input("How many tries do you want >>> "))
money = 500
bet = int(input("How much do you want to bet >>>"))
winnings = bet*rngone/tries-bet
winnings = int(winnings)
if bet > money:
print("You can't bet more money than you have")
for i in range(tries):
answer = random.randint(1, rngone)
guess = int(input("Guess! >>> "))
if guess == answer:
money = money + winnings
print("CONGRADULATIONS! You won!", winnings ,"You now have", money,"dollars.")
elif guess != answer:
money = money - bet
print("Not quite!", answer,"was the answer. You lost",bet, "you now have",money)
if money == 0:
exit()
elif i == tries:
print("You ran out of tries.")
break
试试这个
创建一个函数来检查用户是否仍有余额
如果为true,那么创建一个“for循环”,这是python中的一个命令。我建议您研究一下这个函数,以便能够适应您的代码
相关问题 更多 >
编程相关推荐