if matches in ticket我的函数在该点之后立即停止工作,matches将错误列为无效输入。这是什么原因,我该如何解决?我对 Python 很陌生,所以非常感谢任何帮助。此外,此功能仍在进行中,我认识到它目前的效率非常低,但我正在尝试在更改其他任何内容之前修复此错误。
import random
def matches(ticket, winner):
score = 0
attemptnum = 0
for number in ticket:
if number in winner:
score += 1
return score
def winner():
win1 == rand.randint(1, 69)
win2 == rand.randint(1, 69)
win3 == rand.randint(1, 69)
win4 == rand.randint(1, 69)
win5 == rand.randint(1, 69)
win6 == rand.randint(1, 69)
winner == 'win1 win2 win3 win4 win5 win6'
def playPowerBall():
print('Please select your first unique number between 1-69.')
def ticket():
num1 = int(input('1st Number:'))
if num1 in winner():
score += 1
matches += 1
else:
score += 0
matches += 0
num2 = int(input('2nd Number:'))
if num2 in winner():
score += 1
matches += 1
else:
score += 0
matches += 0
num3 = int(input('3rd Number:'))
if num3 in winner():
score += 1
matches += 1
else:
score += 0
matches += 0
num4 = int(input('4th Number:'))
if num4 in winner():
score += 1
matches += 1
else:
score += 0
matches += 0
num5 = int(input('5th Number:'))
if num5 in winner():
score += 1
matches += 1
else:
score += 0
matches += 0
num6 = int(input('6th Number:'))
if num6 in winner():
score += 1
matches += 1
else:
score += 0
matches += 0
attempts = num1, num2, num3, num4, num5, num6
for matches in ticket:
score += 1
else:
score += 0
if matches in ticket:
print('You picked at least ' matches 'winning numbers in 6 attempts, please claim your cash prize.')
else:
print('You do not have a winning combination. Would you like to play Powerball again?')
response = str(raw_input('Y/N:')):
if response == 'Y':
os.execl(sys.executable, sys.executable, *sys.argv)
else:
print('Thank you for playing.')
sys.exit(0)