title: Compare two digit numbers for a lottery program in Python
body: <p>I have an assignment in my python class that I'm struggling with.</p>
  
  <h2>Program</h2>
  
  <p>Here's the basic premise:
  Lottery Program. The program randomly generates a two-digit number, prompts the user to enter a two-digit number, and determines whether the user wins according to the following rules:</p>
  
  <ol>
  <li>If the user's input matches the lottery in the <em>exact</em> order, the award is $10,000</li>
  <li>If all the digits in the user's input match all the digits in the lottery number, the award is $1,000</li>
  <li>If one digit in the user's input matches a digit in the lottery number, the award is $1,000</li>
  </ol>
  
  <h2>Basic format</h2>
  
  <p>Basically, I use randint to generate a two digit number (like say it generates 58)
  Then the <em>user</em> inputs a number of the same length (Although it's not specified, but for the sake of simplicity lets say the number is 10 to 99)</p>
  
  <p>Then through a series of nested ifs the numbers are compared to 3 results and 1 exception.</p>
  
  <h2>Problem:</h2>
  
  <p>I don't have a clue as two how I compare the numbers in the way specified. I know all the basic operators, but in this case I don't see a way to use them (Except the perfectly matching numbers where you can use ==). I was thinking of an array (from my C/C++ class), but I'm not sure how to implement it here. Here's what I've done so far:</p>
  
  <pre><code>import random
  import time
  
  ##Declare Variables
  usernum=0.0
  lottery_num=random.randint(10,99)
  ##Input
  print("Welcome to the Lottery Program!")
  usernum=int(input("Please enter a two digit number: "))
  print("Calculating Results.")
  for i in range(3):
    time.sleep(1)
    print(".")
  ##Calc &amp; Output
  if lottery_num==usernum:
    print("All your numbers match in exact order! Your reward is $10,000!\n")
  elif lottery_num==                #WHAT DO HERE?
    print("All your numbers match! Your reward is $3,000!\n")
  elif lottery_num==                #WHAT DO HERE?
    print("One of your numbers match the lottery. Your reward is $1,000!\n")
  else:
   print("Your numbers don't match! Sorry!")
  </code></pre>
  
  <h2>Solution</h2>
  
  <p>I've finally figured out how to do it with much help from you guys! Thank you very much! Here's the complete assignment for those interested as to what I did.</p>
  
  <pre><code>import random
  import time
  
  ##Declare Variables
  user_num=0
  ##lottery_num=random.randint(10,99)
  lottery_num=12
  
  ##Input
  print("Welcome to the Lottery Program!")
  user_num=int(input("Please enter a two digit number: "))
  print("Calculating Results.")
  for i in range(3):
    time.sleep(1)
    print(".")
  
  ##Calc &amp; Output
  lottery_tens = lottery_num // 10
  lottery_ones = lottery_num % 10
  
  user_tens = user_num // 10
  user_ones = user_num % 10
  
  if lottery_num == user_num:
      print("All your numbers match in exact order! Your reward is $10,000!\n")
  elif lottery_tens == user_ones and lottery_ones == user_tens:
      print("All your numbers match! Your reward is $3,000!\n")
  elif lottery_tens == user_tens or lottery_ones == user_ones \
    or lottery_ones == user_tens or lottery_tens == user_ones:
      print("One of your numbers match the lottery. Your reward is $1,000!\n")
  else:
      print("Your numbers don't match! Sorry!")
  
  ##Same as Calc &amp; Output using Sets.
  ##lottery_set = set('%02d' % lottery_num)
  ##user_set = set('%02d' % user_num)
  ##if lottery_num == user_num:
  ##    print("All your numbers match in exact order! Your reward is $10,000!\n")
  ##elif lottery_set == user_set:
  ##    print("All your numbers match! Your reward is $3,000!\n")
  ##elif lottery_set.intersection(user_set):
  ##    print("One of your numbers match the lottery. Your reward is $1,000!\n")
  ##else:
  ##    print("Your numbers don't match! Sorry!")
  </code></pre>