I am attempting to create a function that evaluate user input against a randomly generated 'winner' sequence. The code will run fine until after the user's input has been entered, where it will stop. The editor I use is a bit strange as well, so the indentation will be off here, however, I promise that it is NOT the issue. Sorry about that. Thank you
from __future__ import print_function
import random
import sys
minimum, maximum = 1,69
def playPowerBall():
instruction = "Please pick your {} number, between 1 and 69:"
tickets = []
for s in ('1st', '2nd', '3rd', '4th', '5th', '6th'):
ticket = int(input(instruction.format(s)))
tickets.append(ticket)
range = (1,69)
if any(ticket < minimum or ticket > maximum for ticket in tickets):
print('One or more of the inputted numbers is not between 1-69. Please restart the function and try again.')
sys.exit()
winners = []
for s in ('1st', '2nd', '3rd', '4th', '5th', '6th'):
winner = random.sample(range(0,69), 6)
winners.append(winner)
def matches(tickets, winners):
score = 0
for number in tickets:
if number in winners:
score += 1
else:
score += 0
return score
if 3 <= score:
print('You picked at least three winning numbers, please claim your cash prize.')
else:
print('You do not have a winning combination. Would you like to play Powerball again? (Y/N)')
response = str(input('Y/N:'))
if response == 'Y':
sys.restart()
else:
sys.exit()
答案 0 :(得分:0)
您正在用语句range
覆盖内置函数range = (1, 69)
,然后执行winner = random.sample(range(0,69), 6)
,因此,您试图调用元组(1, 69)
。如果删除这样的语句range = (0, 69)
,该错误就会消失。您的代码中还有其他问题,您必须在matches
的末尾调用playPowerBall
,必须从方法return
和{{1}中删除matches
语句}没有sys
函数,但是您可以递归调用restart
:
playPowerBall