简体   繁体   English

我正在看 Mike Dane 关于 Guessing Game 的 Python 教程,但我对代码感到困惑

[英]I'm watching a python tutorial of Mike Dane about Guessing Game and I'm confused about the code

I'm confused about the Guesing Game with the variable out_of_guesses.我对带有变量 out_of_guesses 的猜谜游戏感到困惑。 while guess != guess_number and not (out_of_guesses).而guess != guess_number 而不是(out_of_guesses)。 Because if you use NOT Operator, the out_of_guesses variable will become True, so therefore: while guess is not equal to secret number and not False continue?因为如果使用 NOT 运算符,out_of_guesses 变量将变为 True,因此:虽然guess 不等于秘密数字并且不为 False 继续? so the out_of_guesses variable will go to True and you will lose?所以 out_of_guesses 变量会变为 True 而你会输?

secret_word = "giraffe"
guess_count = 0
guess_limit = 3
guess = ""
out_of_guesses = False
while guess != secret_word and not (out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Enter guess: ")
        guess_count += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("Out of guesses, you lose.")
else:
    print("You win!")

I'm confused about the Guesing Game with the variable out_of_guesses.我对带有变量 out_of_guesses 的猜谜游戏感到困惑。 while guess != guess_number and not (out_of_guesses).而guess != guess_number 而不是(out_of_guesses)。 Because if you use NOT Operator, the out_of_guesses variable will become True, so therefore: while guess is not equal to secret number and not False continue?因为如果使用 NOT 运算符,out_of_guesses 变量将变为 True,因此:虽然guess 不等于秘密数字并且不为 False 继续? so the out_of_guesses variable will go to True and you will lose?所以 out_of_guesses 变量会变为 True 而你会输?

secret_word = "giraffe"
guess_count = 0
guess_limit = 3
guess = ""
out_of_guesses = False
while guess != secret_word and not (out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Enter guess: ")
        guess_count += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("Out of guesses, you lose.")
else:
    print("You win!")

I'm confused about the Guesing Game with the variable out_of_guesses.我对带有变量 out_of_guesses 的猜谜游戏感到困惑。 while guess != guess_number and not (out_of_guesses).而guess != guess_number 而不是(out_of_guesses)。 Because if you use NOT Operator, the out_of_guesses variable will become True, so therefore: while guess is not equal to secret number and not False continue?因为如果使用 NOT 运算符,out_of_guesses 变量将变为 True,因此:虽然guess 不等于秘密数字并且不为 False 继续? so the out_of_guesses variable will go to True and you will lose?所以 out_of_guesses 变量会变为 True 而你会输?

secret_word = "giraffe"
guess_count = 0
guess_limit = 3
guess = ""
out_of_guesses = False
while guess != secret_word and not (out_of_guesses):
    if guess_count < guess_limit:
        guess = input("Enter guess: ")
        guess_count += 1
    else:
        out_of_guesses = True
if out_of_guesses:
    print("Out of guesses, you lose.")
else:
    print("You win!")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM