FAQ: Learn Python - Conditionals & Control Flow - The Big If

This community-built FAQ covers the “The Big If” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise The Big If:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

Hi there! I’m getting an unexpected indent, however I didn’t change the template only the values

1 Like

Can someone explain this to me? I am very confused.

The code doesn’t refresh when I start ‘15. The Big if’. Instead, the correct code from ‘14.I Got 99 Problems, But a Switch Ain’t One’ remains in script.py. In an effort to work around this I manually wrote the correct code. However, this error message keeps appearing… can anyone help?

I see this was posted a little while ago. Just in case you or anyone else has/is run into this issue:
You do not need to put a bool after the else in line 16. Your program is unable to understand your expression after the : . All other statements look correct. So your program will already be able to deduce that anything below 65 will register as a F.

Please let me know if I explained this correctly. It sounds right in my head.

I also felt the need to add the “and grade < 90”, “and grade < 80”, etc., because I thought
a grade of “75” might return a grade of C and D and F. But, it turns out that wasn’t necessary. Can someone explain why? Is Python just reading top-down, so once it assigns a value it doesn’t continue down the line to see what else might apply to it? I hope that makes sense.

If .. elif .. else statements are always top, down and only one branch can ever be followed (the one in which the condition is satisfied). If none of the branches are followed in the absence of an else clause, then nothing is returned from the function, otherwise the else clause is the default branch.

I found it simpler to start with the lowest value and gradually work up to the highest.


if   x < 60: y = 'F'
elif x < 70: y = 'D'
elif x < 80: y = 'C'
elif x < 90: y = 'B'
else:        y = 'A'
return y

I don’t understand the comparators >= and <= what do they mean?

@mtf please reply.DON’T UNDERSTAND!

These operators represent either inequality, as in one value is different from the other, either greater than or less than, respectively, or they represent equality if both values are the same.

6 > 7   =>  False

6 >= 7  =>  False

6 < 7   =>  True

6 <= 7  =>  True

The above is rather moot, being literal. We’re more likely to be comparing two variables which may be dynamic in nature, or user input compared to a dynamic value or a static literal in the code.

Can someone explain why my code did not work? I now understand that the if else statements go from top to down order so using and statements like I did are not necessary, but I dont understand why using and like I did should still not work? Why is it not printing the correct results?

# Complete the if and elif statements!
def grade_converter(grade):
    if grade >= 90:
        return "A"
    elif grade > 79 and grade < 90:
        return "B"
    elif grade > 69 and grade > 80:
        return "C"
    elif grade > 64 and grade < 70:
        return "D"
        return "F"
# This should print an "A"      
print grade_converter(92)

# This should print a "C"
print grade_converter(70)

# This should print an "F"
print grade_converter(61)

Looks like you put a > instead of a <

that should be

    elif grade > 69 and grade < 80:
        return "C"

Thanks. I figured it out by myself after looking at the code for some time.

Complete the if and elif statements!

def grade_converter(grade):
if grade >= 90:
return “A”
elif grade >= 80 - 89:
return “B”
elif grade >=70 and grade <= 79:
return “C”
elif grade >= 65 - 69:
return “D”
return “F”

This should print an “A”

print grade_converter(92)

This should print a “C”

print grade_converter(70)

This should print an “F”

print grade_converter(61)

Alguém poderia me ajudar com esse exercício?
Estou presa a muito tempo. Já li varias dicas de respostas anteriores e não chega na solução

no console aparece o retorno “A” e “B” mas o C da erro. repete o “B”

Something is amiss with this signature line…

As a consideration, something less than 60 is just that.

if x < 60:
    return "F"

We have ruled out the failure off the top. And, we know that the mark will pass, after this point in the logic. It’s really just climbing a ladder…

def get_letter_grade(x):
    if x < 60:
        return "F"
    if x < 70:
        return "D"
    if x < 80:
        return "C"
    if x < 90:
        return "B"
    if x < 100:
        return "A"
    if x == 100:
        return "A+"
    raise ValueError
>>> get_letter_grade(101) # Reaching for the rung that is not there
Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
  File "<pyshell#24>", line 14, in get_letter_grade
    raise ValueError
>>> get_letter_grade(100)
>>> get_letter_grade(99)
>>> get_letter_grade(89)
>>> get_letter_grade(79)
>>> get_letter_grade(69)
>>> get_letter_grade(59)

As crude as this may appear, it is tolerant of floats, which is something that so many examples posted in these forums would fail at. If we’re meant to have intervals, then make sure there are no gaps between them.