如果命令在python - 轮盘模拟器

时间:2013-03-30 15:22:38

标签: python if-statement printing

我正在尝试以最小,最大和特定增量请求特定的投注金额。当我运行以下代码时,程序循环遍历数组中的每个元素而不是停止。

from pylab import *
import random
bank = 20000
betrange=range(100,20100,100)    
print "Hello Kathy, welcome to the Golden Brighton casino. We have reserved a high roller table for your bank of 20,000. How much would you like to bet per spin? The table has a 100 minimum bet with a maximum of 20,000."
print "The available legal bets are as follows:"
bet=raw_input("Place your bets please:") 
for i in range(len(betrange)):
    if betrange[i] == bet: 
       print bet,"Your bet has been accepted, can you make a million?"
       break
    else:
       print bet,"Please enter a legal bet. The table minimum is 100, with a maximum of 20000 in increments of 100."

1 个答案:

答案 0 :(得分:3)

看起来你的代码作为表达式而不是循环会更好:

if 100 <= bet <= 20000 and bet%100 == 0:
    print bet,"Your bet has been accepted"
else:
    print bet,"Please enter a valid bet"