-2
私はPythonには初めてです。以下では、宝くじの番号が333である場合、Yダニエル梁Pythonの本の第4章 から実践プログラミング演習であるように133、233、433、533、633、733、833、933などの様々なユーザ入力のための完璧な試合を取得していますなぜ私は考えていない。Pythonの抽選プログラムY Daniel Liangから
#!/usr/bin/env python3
#import random
lottery = 333 #random.randint(100, 999)
guess = int(input("\nEnter a three-digit number: "))
print("\nThe Lottery Number is:", lottery)
lottery_digit1 = lottery // 100
lottery %= 100
lottery_digit2 = lottery // 10
lottery_digit3 = lottery % 10
guess_digit1 = guess // 100
guess %= 100
guess_digit2 = guess // 10
guess_digit3 = guess % 10
if guess == lottery:
print("Perfect Match: First Prize $10,000")
elif (guess_digit1 == lottery_digit1 or
guess_digit1 == lottery_digit2 or
guess_digit1 == lottery_digit3) and \
(guess_digit2 == lottery_digit1 or
guess_digit2 == lottery_digit2 or
guess_digit2 == lottery_digit3) and \
(guess_digit3 == lottery_digit1 or
guess_digit3 == lottery_digit2 or
guess_digit3 == lottery_digit3):
print("Matching All Digits: Second Prize $3,000")
elif (guess_digit1 == lottery_digit1 or
guess_digit1 == lottery_digit2 or
guess_digit1 == lottery_digit3) or \
(guess_digit2 == lottery_digit1 or
guess_digit2 == lottery_digit2 or
guess_digit2 == lottery_digit3) or \
(guess_digit3 == lottery_digit1 or
guess_digit3 == lottery_digit2 or
guess_digit3 == lottery_digit3):
print("Matching a Single Digit: Third Prize $1,000")
else:
print("Nice Try.")
はスパゲッティコードを書く方法についての教科書から、このですか? –