dimanche 6 mars 2016

Lottery Program (Beginner at Python)

Basically for my introduction to programming using python class, we were assigned this "Lottery Program". Essentially, 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:

  1. if the user's input matches the lottery in the exact order, the award is $10,000
  2. if all the digits in the user's input match all the digits in the lottery number, the award is $3,000
  3. if one digit in the user's input matches a digit in the lottery number, the award is $1,000

I just need help on letting the program randomly generate a random number... Could someone help me figure out what I'm doing wrong? I can't seem to figure out how to let the computer generate its own random two digit number.

Should I be adding a "lottery = random.randint(10, 99)" somewhere in my code?

Here's the code I came up with so far: (I apologize for the format if it seems a little off, it's my first time using this website)

This program is used to generate a two-digit number

randomly by the user:

import random

usernum = 0
lotterynum = 36

print("\t\t\tWelcome to the Lottery Game!")
usernum = int(input("Enter a two digit number to guess: "))

lotteryNum1 = lotterynum // 10
lotteryNum2 = lotterynum % 10

userNum1 = usernum // 10
userNum2 = usernum % 10

lottery = 36
print("\nThe lottery number is:", lottery)

if lotterynum == usernum:
    print("Congrats! You guessed the lottery number in order! \
    You won $10,000!")
elif lotteryNum1 == userNum2 and lotteryNum2== userNum1:
    print("All your numbers match the lottery! You won $3,000!")
elif lotteryNum1 == userNum1 or lotteryNum2 == userNum2 \
     or lotteryNum2 == userNum1 or lotteryNum1 == userNum2:
    print("One of your numbers match the lottery! You won $1,000!")

else:
    print("Your numbers don't match! Try again.")




Aucun commentaire:

Enregistrer un commentaire