जब भी उपयोगकर्ता एक नई शर्त लगाता है, तो मैं हर बार एक नया यादृच्छिक संख्या बनाने के लिए अपना प्रोग्राम कैसे प्राप्त करूं, वर्तमान में यह हर बार जब मैं इसे चलाता हूं तो यह केवल ब्लैक 2 नंबर का उत्पादन करेगा। साथ ही विषम उत्पन्न संख्याएं लाल और यहां तक ​​कि काली भी होनी चाहिए।

import random 

def roulette_wheel():
    # opening interface
    print("Welcome to the Roulette Wheel \nYou currently have $100 \nEnter a number 0-36 to bet on a number, -1 to bet on Black, -2 to bet on Red, or -3 to walk away. ")

    #amount of money that the user begins with
    user_flow = 100

    while user_flow >= 1:
        user_bet = input("What will you do:")
        number = random.randint(1,36) 
        for number in (1, 35, 2):
            color = ('red')
        for number in (2, 36,2):
            color = ('black')

        # betting on black
        if user_bet == '-1':
            print("You are betting on black")
            money = int(input("What is your bet:$"))
            print('The result of the spin was', color, number)
            if color == 'black':
                user_flow = 2 * money + user_flow
                print('Congrats! You now have $%d' %(user_flow)) 
            else:
                user_flow = user_flow - money
                print('Sorry! You now have $%d' %(user_flow))

      `
2
marty_mcfly 4 अक्टूबर 2017, 23:52

2 जवाब

ऐसा लगता है कि आप लूप में number को अधिलेखित कर देते हैं?

    number = random.randint(1,36) 
    for number in (1, 35, 2):
        color = ('red')

इसके बजाय निम्नलिखित करने के बारे में क्या?

    number = random.randint(1,36) 
    for value in (1, 35, 2):
        if number == value:
            color = ('red')

Fwiw, एक आसान तरीका है

    number = random.randint(1,36) 
    if (number%2) = 1:
        color = ('red')
    else:
        color = ('black')
0
Gilles Gouaillardet 5 अक्टूबर 2017, 04:32

random.randint() के बजाय random.choice() का उपयोग कैसे करें?

import random 

def roulette_wheel():
    # opening interface
    print("Welcome to the Roulette Wheel \nYou currently have $100     \nEnter a number 0-36 to bet on a number, -1 to bet on Black, -2 to bet on Red, or -3 to walk away. ")

    #amount of money that the user begins with
    user_flow = 100

    while user_flow >= 1:
        user_bet = input("What will you do:")

        # betting on black
        if user_bet == '-1':
            print("You are betting on black")
        elif user_bet == '-2':
            print("You are betting on red")
        elif user_bet == '-3':
            break # exit here
        else:
            user_bet = int(user_bet)
            print("You are betting on {0}".format(user_bet))

        money = int(input("What is your bet: $"))

        value = random.choice(
            ([1,'red'],
            [2,'black'],
            [35,'red'],
            [36, 'black']))

        color =  value[1]
        number = value[0]

        print('The result of the spin was', color, number)
        if user_bet == '-1' and color == 'black':
            user_flow = 2 * money + user_flow
            print('Congrats! You now have $%d' %(user_flow))
        if user_bet == '-2' and color == 'red':
            user_flow = 2 * money + user_flow
            print('Congrats! You now have $%d' %(user_flow)) 
        if user_bet > 0 and user_bet == number:
            user_flow = 2 * money + user_flow
            print('Congrats! You now have $%d' %(user_flow)) 
        else:
            user_flow = user_flow - money
            print('Sorry! You now have $%d' %(user_flow))
0
LegendaryJLD 5 अक्टूबर 2017, 16:37