轮盘赌赢得和失去

时间:2016-10-02 03:27:10

标签: python

#This is a roulette wheel

import random 
import time
#Randomiser
green = [0]
red = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35]
black = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36]
spin = random.randint (0,36)
#Program
bet = int(input("Enter your Bets: "))
colour = input("Pick your Colour: ")
print ("The wheel is spinning")

if spin in green:
    print ("The ball stopped on green")
    print ("You won",bet*100,"!")

if spin in red:
    print ("The ball stopped on red")
    print ("You won",bet*2,"!")

if spin in black:
    print ("The ball stopped on black")
    print ("You won",bet*2,"!")

它告诉某人是否赢了。但它无法判断是否有人输了。我已经学习了几个月的python,并且想知道是否有人可以帮助我。谢谢!

3 个答案:

答案 0 :(得分:0)

也许我不知道轮盘赌的规则,但似乎你已将它编码为始终打印"祝贺你赢了!"

首先,你需要将玩家选择(颜色)分配给可测试的值,在我们的例子中是您设置的列表:

if "red" in colour:
    colour = red

你显然会在这里添加其他颜色。

接下来你需要针对旋转值测试玩家的选择,这样的东西会起作用,你显然需要修改它以适合你的程序:

if spin in colour:
    print("you win")
else:
    print("you lose")

然后根据需要修改获胜结果

答案 1 :(得分:0)

0外,奇数是红色,偶数是绿色。所以这对你来说会更好:

import random

bet = int(input("Enter your Bets: "))
colour = input("Pick your Colour: ")
print ("The wheel is spinning")

spin = random.randrange(0,37)

if spin == 0:
    print ("The ball stopped on green")
    print ("You won",bet*100,"!")

print ("The ball stopped on", ['black', 'red'][spin%2])
elif ['black', 'red'][spin%2] == color:
    print ("You won",bet*2,"!")
else:
    print ("You lost!")

答案 2 :(得分:-1)

if spin in green:
    winning_color = "green"
    print("The ball landed on", winning_color)
if spin in red:
    winning_color = "red"
    print("The ball landed on", winning_color)
if spin in black:
    winning_color = "black"
    print("The ball landed on", winning_color)

if winning_color == colour:
    print("Congrats you won!")
    print("You won", bet*2, "!")

else:
    print("Sorry you lose")

要注意的事项,你应该使用

if somethingHappens:
    doSomething
elif somethingElseHappens:  #Stands for else if, must be after the first if
    doThisInstead
else:  #This is Pythons catchall if the conditions above fail, this will run
    doThisIfNothingElse