I’m writing a program that simulates a lottery game, and I’m stuck at a certain point. I’m trying to match the user’s guesses with the numbers on the winning ticket, but my function “checkmatch” apparently takes 2 arguments, but I’m only giving it 1? I know there are similar questions on the site, but I’m a very novice programmer, and the others seemed… a bit above me. This is my program in its entirety (thus far):
import random
def main():
random.seed()
#Prompts the user to enter the number of tickets they wish to play.
tickets = int(input("How many lottery tickets do you want?\n"))
#Creates the dictionaries "winning_numbers" and "guess"
winning_numbers = []
guess = []
#Generates the winning lotto numbers.
for i in range(tickets):
del winning_numbers[:]
del guess[:]
a = random.randint(1,30)
winning_numbers.append(a)
b = random.randint(1,30)
while not (b in winning_numbers):
winning_numbers.append(b)
c = random.randint(1,30)
while not (c in winning_numbers):
winning_numbers.append(c)
d = random.randint(1,30)
while not (d in winning_numbers):
winning_numbers.append(d)
getguess(guess, tickets)
nummatches = checkmatch(guess)
nummisses = checkmiss()
#print(winning_numbers)
#Gets the guess from the user.
def getguess(guess, tickets):
del guess[:]
for i in range(tickets):
bubble = input("What numbers do you want to choose for ticket #"+str(i+1)+"?\n").split(" ")
guess.append(bubble)
#Checks the user's guesses with the winning numbers.
def checkmatch(winning_numbers, guess):
match = 0
for i in range(5):
if winning_numbers[i] == guess[i]:
match = match+1
return match
And this is the part that is giving me trouble:
def checkmatch(winning_numbers, guess):
match = 0
for i in range(5):
if winning_numbers[i] == guess[i]:
match = match+1
return match
And here is what I get when I try a test run:
How many lottery tickets do you want?
3
What numbers do you want to choose for ticket #1?
1 2 3 4 5
What numbers do you want to choose for ticket #2?
1 2 3 4 5
What numbers do you want to choose for ticket #3?
1 2 3 4 5
Traceback (most recent call last):
File "C:/Users/Ryan/Downloads/Program # 2/Program # 2/lottery.py", line 64, in <module>
main()
File "C:/Users/Ryan/Downloads/Program # 2/Program # 2/lottery.py", line 36, in main
checkmatch(guess)
TypeError: checkmatch() takes exactly 2 arguments (1 given)
Thank you for any and all help!
The problem is
In your code
checkmatchtakes 2 argumentswinning_numbers & guessbut when you are calling it you are only giving a single argument.Like for example