简体   繁体   中英

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. while guess != guess_number and not (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? so the out_of_guesses variable will go to True and you will lose?

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. while guess != guess_number and not (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? so the out_of_guesses variable will go to True and you will lose?

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. while guess != guess_number and not (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? so the out_of_guesses variable will go to True and you will lose?

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!")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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