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。使用!=给出异或,又名异或。

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 回答