I am fairly new to Python
and I am doing a "Lottery Game."
I should note I am using Python 3.4.2
and the Python GUI
.
The program is a Lottery Game in which it:
- Generates two random numbers, each between 0 and 9
- Allow the user to guess two numbers (between 0 and 9)
- Prompts the user with an appropriate message for entering input
- Compares each of the user’s guesses to the two random numbers and display a message that includes the user’s guess as a 2 digit number
For the game, depending on what you guess, you win based on these conditions:
- Any one matching ----> $1000
- Two matching, not in order ----> $10,000
- Two matching in exact order ----> $100,000
- No matches ----> $0
I would, for example, guess 4 5 and the random numbers generated would be 6 4 but I would get $0 or "No Matches."
I think the error lies in being unable to get the "Any one matching" correct, or this snippet of code:
elif guess1 == number1 | guess1 == number2 | guess2 == number1 | guess2 == number2:
number1 = str(number1)
number2 = str(number2)
guess1 = str(guess1)
guess2 = str(guess2)
print('Your guess was ' + guess1 + guess2)
print('The lottery number is ' + number1 + number2)
print('Congrats, you win 1,000')
Here is my code I wrote:
import random
number1 = random.randint(0, 9)
number2 = random.randint(0, 9)
print('Welcome to the Lottery Game! You must guess two numbers.')
print('Guess a number from 0 - 9')
guess1 = input()
guess1 = int(guess1)
print('Guess a number from 0 - 9')
guess2 = input()
guess2 = int(guess2)
if guess1 == number1 & guess2 == number2:
number1 = str(number1)
number2 = str(number2)
guess1 = str(guess1)
guess2 = str(guess2)
print('Your guess was ' + guess1 + guess2)
print('The lottery number is ' + number1 + number2)
print('Congrats, you win 100,000')
elif guess1 == number2 & guess2 == number1:
number1 = str(number1)
number2 = str(number2)
guess1 = str(guess1)
guess2 = str(guess2)
print('Your guess was ' + guess1 + guess2)
print('The lottery number is ' + number1 + number2)
print('Congrats, you win 10,000')
elif guess1 == number1 | guess1 == number2 | guess2 == number1 | guess2 == number2:
number1 = str(number1)
number2 = str(number2)
guess1 = str(guess1)
guess2 = str(guess2)
print('Your guess was ' + guess1 + guess2)
print('The lottery number is ' + number1 + number2)
print('Congrats, you win 1,000')
else:
number1 = str(number1)
number2 = str(number2)
guess1 = str(guess1)
guess2 = str(guess2)
print('Your guess was ' + guess1 + guess2)
print('The lottery number is ' + number1 + number2)
print('Sorry, you win nothing.')
Any help would be greatly appreciated!