我对Python
相当新,我正在做一个"彩票游戏。"
我应该注意我使用的是Python 3.4.2
和Python GUI
。
该计划是一个彩票游戏,其中:
对于游戏,根据您的猜测,您可以根据以下条件获胜:
我认为错误在于无法获得"任何一个匹配"正确的,或这段代码:
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')
这是我写的代码:
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.')
非常感谢任何帮助!