1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Can anyone discover where the bug in this code, when I choose to not play again it...

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 16:42.

  1. Stack

    Stack Membro Participativo

    import random

    random_num = random.randint(1, 100)

    count = 1
    while True:
    try:
    num = int(input("Guess the number? "))

    if num == random_num:
    print("Congrates! you guessed it.")
    print("Tried:", count, "times")

    play = input("Do you want to play again Y/N? ")
    if play.lower() in ['n', 'no']:
    quit()

    elif play.lower() in ['y', 'yes']:
    random_num = random.randint(1, 100)
    count = 1

    else:
    quit()

    elif num > random_num:
    print("Not yet, smaller.")
    elif num < random_num:
    print("Not yet, Greater.")
    else:
    quit()
    count += 1
    except:
    print("Oops! please enter a valid number.")


    When I run this code it runs normally. But when I finish the game and choose to not play again it stuck in infinite loop

    When I run the good and choose n or no it stuck in infinite loop

    Guess the number? Oops! please enter a valid number.


    forever, but what I expecting is to finish the game and end the program.

    Continue reading...

Compartilhe esta Página