Python 巨蟒彩票游戏

Python 巨蟒彩票游戏,python,python-2.7,Python,Python 2.7,这是我第一个完全靠自己完成的项目之一,没有任何教程,我相信这有点草率。现在,我不明白为什么我的奖金总是作为“盒子”型赌注的奖金输出。我还没有完全弄清楚如何表示5位数的箱型赌注,所以部分程序还没有编写。有关于修复betType的帮助或建议吗 #lotto program #Created 04/14/2014, last modified 04/16/14 #4/16/14 made lottery a class, added 4 or 5 digit support #4/16/14 add

这是我第一个完全靠自己完成的项目之一,没有任何教程,我相信这有点草率。现在,我不明白为什么我的奖金总是作为“盒子”型赌注的奖金输出。我还没有完全弄清楚如何表示5位数的箱型赌注,所以部分程序还没有编写。有关于修复betType的帮助或建议吗

#lotto program

#Created 04/14/2014, last modified 04/16/14
#4/16/14 made lottery a class, added 4 or 5 digit support
#4/16/14 added support for box type bets, now program assumes all payouts are for box type bets --UNRESOLVED
from random import *
import time



class Lottery:
def __init__(self, digits, betType, betAmt):
    self.digits = digits
    self.betType = betType
    self.betAmt = betAmt

def winner(self, tries, choice, betType):
    if self.betType.upper() == 'STRAIGHT' or 'S':
        if self.digits == '3':
            if self.betAmt == '1.00':
                payout = 500
            elif self.betAmt == '0.50':
                payout = 250
        elif self.digits == '4':
            if self.betAmt == '1.00':
                payout = 5000
            elif self.betAmt == '0.50':
                payout = 2500
        elif self.digits == '5':
            if self.betAmt == '1.00':
                payout = 50000
            elif self.betAmt == '0.50':
                payout = 25000

#At present I have not figured out how to add payouts for box type bets -- 4/16/2014
    if self.betType.upper() == 'BOX' or 'BOXED' or 'B':
        if self.digits == '3':
            if self.betAmt == '1.00':
                if len(set(choice)) == 3: # 6 way box
                    payout = 83
                elif len(set(choice)) == 2: # 3 way box
                    payout = 167
            elif self.betAmt == '0.50': 
                if len(set(choice)) == 3: # 6 way box
                    payout = 41.5
                elif len(set(choice)) == 2: # 3 way box
                    payout = 83.5
        elif self.digits == '4':
            if self.betAmt == '1.00':
                if len(set(choice)) == 4: #24 way box
                    payout = 200
                elif len(set(choice)) == 3: #12 way box
                    payout = 400
                elif len(set(choice)) == 2:
                    if sorted(choice)[0] == sorted(choice)[1] == sorted(choice)[2]: # 4 way box
                        payout = 1198
                    else: # 6 way box
                        payout = 800 
            elif self.betAmt == '0.50':
                if len(set(choice)) == 4: #24 way box
                    payout = 100
                elif len(set(choice)) == 3: #12 way box
                    payout = 200
                elif len(set(choice)) == 2:
                    if sorted(choice)[0] == sorted(choice)[1] == sorted(choice)[2]: # 4 way box
                        payout = 599
                    else: # 6 way box
                        payout = 400
        elif self.digits == '5':
            if self.betAmt == '1.00':
                if len(set(choice)) == 5: # 120 way box
                    payout = 417
                elif len(set(choice)) == 4: # 60 way box
                    payout = 834
                elif len(set(choice)) == 3: # Still working on all 5 digit box payouts
                    if sorted(choice)[0] == sorted(choice)[1]:
                        pass
            elif self.betAmt == '0.50':
                payout = 25000

    print "-----" * 10
    print "winner after " + str(tries) + " tries!"
    print "It took you " + str(tries/2) + " days to win!"
    print "your tickets cost $" + str(tries * float(self.betAmt)) + ".00"
    print "Your payout was $" + str(payout) + ".00"
    print "Your Net Revenue was $" + str(payout - tries) + ".00"
    print "-----" * 10


def play(self):
    print "<>" * 40
    print "Use 'mp' to play the same 'machine pick' each time"
    print "Use 'ap' to play a new 'machine pick' number each time"
    print "<>" * 40
    guess = raw_input("Choose a lottery number and see how long it takes until you win! >>")
    if guess.upper() == 'MP': #added machine pick option
        if self.digits == '3': #attempt support for 4 and 5 digit numbers
            choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        elif self.digits == '4':
            choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        elif self.digits == '5':
            choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        else:
            pass
    elif guess.upper() == 'AP': #placeholder for autopick in main loop
        pass
    else:
        choice = guess
    tries = 0
    while True:
        if guess.upper() == 'AP': #added machine pick option
            if self.digits == '3': #attempt support for 4 and 5 digit numbers
                choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
            elif self.digits == '4':
                choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
            elif self.digits == '5':
                choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        if self.digits == '3': #attempt support for 4 and 5 digit numbers
            winning = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        elif self.digits == '4':
            winning = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        elif self.digits == '5':
            winning = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
        print winning, choice
        tries += 1
        if self.digits == '3':
            time.sleep(0.02)
        elif self.digits == '4':
            time.sleep(0.002)
        else:
            time.sleep(0.0005)
        if self.betType.upper() == 'STRAIGHT':
            if winning == choice:
                self.winner(tries, choice, self.betType)
                break
        elif self.betType.upper() == 'BOXED' or 'BOX':
            if sorted(winning) == sorted(choice):
                self.winner(tries, choice, self.betType)
                break
class Menu:
def __init__(self):
    #self.game = Lottery(digits, betType, betAmt)
    self.start()
def start(self):
    print "Welcome to the Lottery!"
    self.digits = raw_input("Would you like to play '3' digit, '4' digit, or '5' digit? >> ")
    self.betType = raw_input("Straight, or Boxed bet type? >> ")
    self.betAmt = raw_input("$0.50, or $1.00? >> ")
    self.game = Lottery(self.digits, self.betType, self.betAmt)
    self.game.play()
    raw_input("Enter to play again")

Menu1 = Menu()
#game = Lottery(digits, betType, betAmt)
if __name__ == '__main__':
while True:
    Menu1.start()
#乐透计划
#创建于2014年4月14日,最后修改于2014年4月16日
#2014年4月16日使彩票成为一门课程,增加了4或5位数的支持
#2014年4月16日增加了对箱型投注的支持,现在程序假设所有支付都用于箱型投注——未解决
从随机导入*
导入时间
班级抽奖:
定义初始值(self、digits、betType、betAmt):
self.digits=数字
self.betType=betType
self.betAmt=betAmt
def获胜者(自我、尝试、选择、betType):
如果self.betType.upper()=='stright'或'S':
如果self.digits==“3”:
如果self.betAmt==“1.00”:
支出=500
elif self.betAmt==“0.50”:
支出=250
elif self.digits==“4”:
如果self.betAmt==“1.00”:
支出=5000
elif self.betAmt==“0.50”:
支出=2500
elif self.digits==“5”:
如果self.betAmt==“1.00”:
支出=50000
elif self.betAmt==“0.50”:
支出=25000
#目前,我还没有弄清楚如何为箱型投注增加支付——2014年4月16日
如果self.betType.upper()=='BOX'或'BOX'或'B':
如果self.digits==“3”:
如果self.betAmt==“1.00”:
如果len(设置(选择))==3:#6路盒
支出=83
elif len(设置(选择))==2:#三向盒
支出=167
elif self.betAmt==“0.50”:
如果len(设置(选择))==3:#6路盒
支出=41.5
elif len(设置(选择))==2:#三向盒
支出=83.5
elif self.digits==“4”:
如果self.betAmt==“1.00”:
如果len(设置(选择))==4:#24路盒
支出=200
elif len(设置(选择))==3:#12路盒
支出=400
elif len(设置(选择))==2:
如果已排序(选择)[0]==已排序(选择)[1]==已排序(选择)[2]:#4路框
支出=1198
其他:#6路箱
支出=800
elif self.betAmt==“0.50”:
如果len(设置(选择))==4:#24路盒
支出=100
elif len(设置(选择))==3:#12路盒
支出=200
elif len(设置(选择))==2:
如果已排序(选择)[0]==已排序(选择)[1]==已排序(选择)[2]:#4路框
支出=599
其他:#6路箱
支出=400
elif self.digits==“5”:
如果self.betAmt==“1.00”:
如果len(设置(选择))==5:#120路盒
支出=417
elif len(设置(选择))==4:#60路盒
支出=834
elif len(集合(选择))==3:#仍在处理所有5位数的方框支出
如果已排序(选择)[0]==已排序(选择)[1]:
通过
elif self.betAmt==“0.50”:
支出=25000
打印“----”*10
在“+str(尝试)+”尝试后打印“获胜者!”
打印“你花了多少时间”+str(尝试/2)+“几天就赢了!”
打印“您的票成本$”+str(trys*float(self.betAmt))+“.00”
打印“您的支出为$”+str(支出)+.00”
打印“您的净收入为$”+str(支付-尝试)+.00”
打印“----”*10
def播放(自我):
打印“”*40
打印“每次使用“mp”播放相同的“机器拾取”
打印“每次使用“ap”播放新的“机器拾取”号码”
打印“”*40
guess=原始输入(“选择一个彩票号码,看看你中奖需要多长时间!>>”)
如果guess.upper()='MP':#添加了机器拾取选项
如果self.digits=='3':#尝试支持4位和5位数字
choice=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
elif self.digits==“4”:
choice=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
elif self.digits==“5”:
choice=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
其他:
通过
elif guess.upper()='AP':#主循环中自动拾取的占位符
通过
其他:
选择=猜测
尝试=0
尽管如此:
如果guess.upper()='AP':#添加了机器拾取选项
如果self.digits=='3':#尝试支持4位和5位数字
choice=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
elif self.digits==“4”:
choice=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
elif self.digits==“5”:
choice=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
如果self.digits=='3':#尝试支持4位和5位数字
winning=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
elif self.digits==“4”:
获胜=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
elif self.digits==“5”:
获胜=str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))+str(randint(0,9))
印刷制胜,选择
尝试次数+=1
如果self.digits==“3”:
睡眠时间(0.02)
elif self.digits==“4”:
睡眠时间(0.002)
其他:
睡眠时间(0.0005)
如果self.betType
if self.betType.upper() == 'BOX' or 'BOXED' or 'B'
if (self.betType.upper() == 'BOX') or (self.betType.upper() == 'BOXED') or (self.betType.upper() =='B')
if (self.betType.upper() == 'BOX')   # either True or False
if ('BOXED')  # this will ALWAYS evaluate to True
if ('B')     # this will also always evaluate to True
 if self.betType.upper() == 'STRAIGHT' or 'S':
if (self.betType.upper() == 'STRAIGHT') or ('S')
if 'S':
    print('huh?')