I would split user and computer creation of random numbers up like this:
import random
def computer_random():
"""let computer create a list of 6 unique random integers from 1 to 50"""
ci = random.sample(range(1,50), 6)
return ci
def user_random():
"""let user create a list of 6 unique random integers from 1 to 50"""
print "Enter 6 random integers from 1 to 50:"
ui = []
while len(ui) < 6:
print len(ui) + 1,
i = input("--> ")
# check if i is unique and has a value from 1 to 50
# otherwise don't append, could also assure that i is an integer
if (i not in ui) and (1 <= i <= 50):
ui.append(i)
return ui
comp_list = computer_random() # assign the returned list to variable comp_list
print comp_list # test it
user_list = user_random()
print user_list # test it
Function comp_random() will be called numerous times, each time you need to compare comp_list with user_list. Now you have to work on list compare function to find the matches, then count how many times 3 to 6matches have occured.
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
Offline 1,422 posts
since Jul 2005