Python中的36号轮盘赌模拟

问题描述 投票:0回答:1

我正在尝试创建一个轮盘赌模拟器,我可以在至少 10 个数字上下注,即在一个数字上投注 0.50 美分,如果该数字击中,我的钱将得到 x 36,我还希望它在击中时显示我的余额。但目前为止我只能让它押在一个号码上。我将不胜感激任何帮助

这就是我目前所拥有的

import random

balance = 100

def start():
    global balance
    print("place your bet!: ")
    bet = int(input(">"))
    if bet > balance:
        insufficient_funds()
    else:
        simulate(bet)

def insufficient_funds():
    print("oops not enough money bucko")
    start()

def simulate(bet_amount):
    global balance
    print("choose a number between 0-36: ")
    answer = input("> ")
    result = random.randint(0, 36)
    if result == answer:
        print ("You won")
        balance = bet_amount * 36
        print(f"your balance is now{balance}")
        start()
    else:
        print ("you lost")
        balance -= bet_amount
        print(f"your balance is now {balance}")
        start()

start()
python
1个回答
0
投票

如果您希望用户能够输入多个数字,只需在

for
循环中询问数字,然后将数字添加到列表中即可。这看起来像:

import random

answer_list = []
balance = 100

def start():
    global balance
    print("Place your bet: ")
    bet = int(input("> "))
    if bet > balance:
        insufficient_funds()
    else:
        simulate(bet)

def insufficient_funds():
    print("Oops, not enough money, bucko.")
    start()

def simulate(bet_amount):
    global balance
    print("Choose a number between 0 and 36: ")
    for count in range(0, 36):
        answer = input("> ")
        answer_list.append(int(answer))
        result = random.randint(0, 6)
    num_correct = False
    for count in range(0, len(answer_list)):
        if result == answer_list[count]:
            print("You won!")
            balance += bet_amount
            print(f"Your balance is now {balance}")
            num_correct = True
            start()
    if not num_correct:
        print("You lost.")
        balance -= bet_amount
        print(f"Your balance is now {balance}")
        print(f"The answer was {result}")
        start()

start()

我也不知道为什么你每次都要将余额变量更改为下注乘以 16,所以现在代码只是将下注添加到余额中,而不相乘任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.