[Python] '<' not supported between instances of 'NoneType' and 'int' django views.py

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    templates/html

    {% if guess == rand_num %}
    <h1>{{message1}}</h1>
    {% elif guess > rand_num %}
    <h1>{{message3_a}}</h1>
    <h1>{{message3_b}}</h1>
    {% elif guess < rand_num %}
    <h1>{{message2_a}}</h1>
    <h1>{{message2_b}}</h1>
    {% endif %}


    views.py

    def easy(request, ):
    rand_num = random.choice(lst)
    print(rand_num)
    attempts = 11
    for _ in range(0, 10):
    # print(f"You have {attempts} remaining to guess the number.")
    # guess = int(input("Make a guess: "))
    guess = request.GET.get('guessed_number')
    if guess == rand_num:
    return render(request, 'easy.html', {'attempts': attempts, "message1": f"You got it! The anshwer was {rand_num}"})
    break
    elif guess < rand_num:
    attempts -= 1
    return render(request, 'easy.html', {'attempts': attempts, "message2_a": "Too Low", "message2_b": "Guess again"})
    elif guess > rand_num:
    attempts -= 1
    return render(request, 'easy.html', {'attempts': attempts, "message3_a": "Too High", "message2_b": "Guess again"})
    attempts -= 1
    return render(request, 'easy.html', {'attempts': attempts, 'guess': guess, 'rand_num': rand_num})
    return render(request, 'easy.html')


    I am trying to run this Django code, but it is not working..

    Continue reading...

Compartilhe esta Página