The only thing I haven’t figured out is the 1000 dollar prize. Is it,
matching last digit or \
last two digits match last digit or \
all three digits match last digit
?
Pardon my confusion.
Here is a test sequence based upon what I’ve discrened from the OP code…
import itertools
def result(g, d):
# exact match
if g == d: return "You have won 10,000 dollars!"
# same digits, different order
if tuple(d) in itertools.permutations(tuple(g), 3): return "You have won 3,000 dollars!"
# match one or two positions
match_pos = [ int(g[0] == d[0] and g[0]), int(g[1] == d[1] and g[1]), int(g[2] == d[2] and g[2]) ]
if sum(match_pos) is 0: return "Not a winner."
# match one or two digits
match_digs = [ int(g[0] in d and g[0]), int(g[1] in d and g[1]), int(g[2] in d and g[2]) ]
return "Something matches", match_pos, match_digs, d
print (result(guess, draw))
guess, draw = '456', '416'
print (result(guess, draw))
guess, draw = '456', '461'
print (result(guess, draw))
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
>
Enter a three digit number 789
('Something matches', [0, 8, 0], [7, 8, 0], '187')
('Something matches', [4, 0, 6], [4, 0, 6], '416')
('Something matches', [4, 0, 0], [4, 0, 6], '461')
>
https://repl.it/L7qE
refactoring
import random, itertools
def get_pick():
validRange = range(100, 1000)
while True:
user = ''
while len(user) != 3:
user = input("Enter a three digit number")
if not user.isdigit(): print ("Not a Number"); continue
if int(user) not in validRange: print ("Not in Range"); continue
break
return user
def get_draw():
return str(random.randrange(100, 1000))
def result(g, d):
if g == d: return "You have won 10,000 dollars!"
if tuple(d) in itertools.permutations(tuple(g), 3): return "You have won 3,000 dollars!"
match_pos = ( int(g[0] == d[0] and g[0]), int(g[1] == d[1] and g[1]), int(g[2] == d[2] and g[2]) )
match_digs = ( int(g[0] in d and g[0]), int(g[1] in d and g[1]), int(g[2] in d and g[2]) )
if sum(match_digs) is 0: return "Not a winner."
return "Something matches", match_pos, match_digs, d
guess = get_pick()
draw = get_draw()
print (result(guess, draw))
# arbitrary tests
print (result('456', '416'))
print (result('456', '461'))
print (result('379', '379'))
print (result('379', '937'))
print (result('284', '735'))
https://repl.it/L7qE/1
The short-circuit of all this is is,
print (result(get_pick(), get_draw())