在python2.7.6中,我很难弄清楚如何创建一个菜单类来实例化一个游戏类。我已经搜索了与此相关的其他问题,但是我仍然无法找到如何将参数从一个类传递到另一个类。这也是我第一次问堆栈溢出的问题,所以如果我在这里错误地忽略了我的代码,我很抱歉。在class Lottery:
def __init__(self, digits, betType, betAmt):
self.digits = digits
self.betType = betType
self.betAmt = betAmt
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 digits == '3': #attempt support for 4 and 5 digit numbers
choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
elif digits == '4':
choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
elif 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 digits == '3': #attempt support for 4 and 5 digit numbers
choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
elif digits == '4':
choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
elif digits == '5':
choice = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
if digits == '3': #attempt support for 4 and 5 digit numbers
winning = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
elif digits == '4':
winning = str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9)) + str(randint(0,9))
elif 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 digits == '3':
time.sleep(0.02)
elif digits == '4':
time.sleep(0.002)
else:
time.sleep(0.0005)
if winning == choice:
print "-----" * 10
print "winner after " + str(tries) + " tries!"
print "It took you " + str(tries/2) + " days to win!"
print "your tickets cost $" + str(tries) + ".00"
print "Your payout was $500"
print "Your Net Revenue was $" + str(500 - tries) + ".00"
print "-----" * 10
break
以及
^{pr2}$
任何帮助都将不胜感激,我是Python新手,也堆栈溢出。谢谢:)
^{3}$
这是我在尝试运行程序时遇到的错误。这有帮助吗?对不起,我第一次忘了投递