0
import random

def main():
    number = random.randint(0,100)
    print(number)
    guess = int(input("Enter your guess: "))

    if guess == number :
        print("You win $10,000!")

    elif guess // 10 == number // 10 or guess % 10 == number % 10 :
        print("You win 1,000$!")

    elif guess // 10 == number // 10 and guess % 10 == number % 10 :
        print("You win $3,000!")

    else :
        print("You win $0.")

main()

andこのプログラムは、ステートメントを除いて機能します。誰かが理由を知っていますか?

4

1 に答える 1

0

理由はorカバーandです。!=排他的な or、別名 xor を与える使用。

import random
def main():
    number = random.randint(0,100)
    print(number)
    guess = int(input("Enter your guess: "))

    if guess == number :
        print("You win $10,000!")

    elif (guess // 10 == number // 10) != (guess % 10 == number % 10) :
        print("You win 1,000$!")

    elif guess // 10 == number // 10 and guess % 10 == number % 10 :
        print("You win $3,000!")

    else :
        print("You win $0.")




main()
于 2013-02-21T01:59:34.337 に答える