1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python Program If statement issue [duplicate]

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

  1. Stack

    Stack Membro Participativo

    I am writing my 1st Python program. Why is the boolean variable Did_Well not being set under my if condition ? My code below - My output -

    0 Grade is = B Did well ? True ,85 Grade is = B Did well ? True
    90 Grade is = A Did well ? True, 93 Grade is = A Did well ? True, 40 Grade is = D Did well ? True


    did_well = True
    def calc_grade (score) :

    if score >= 90:
    did_well = True
    return "A"

    elif score >= 80:
    did_well = True
    return "B"

    elif score >= 70:
    did_well = False
    return "C"

    else :
    did_well = False
    return "D"


    for score in [80, 85, 90 , 93, 40]:
    #print ( f{score}, "Grade is " {calc_grade (score)} )
    grade_t = calc_grade (score)
    print ( score, "Grade is = ", grade_t, "Did well ? ", did_well )

    Continue reading...

Compartilhe esta Página