0

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

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."
4

1 回答 1

2

看起来您的代码作为表达式比循环更好:

if 100 <= bet <= 20000 and bet%100 == 0:
    print bet,"Your bet has been accepted"
else:
    print bet,"Please enter a valid bet"
于 2013-03-30T15:25:49.663 回答