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 () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
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.
Eg.
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
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.
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"
else:
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)
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>
get_letter_grade(101)
File "<pyshell#24>", line 14, in get_letter_grade
raise ValueError
ValueError
>>> get_letter_grade(100)
'A+'
>>> get_letter_grade(99)
'A'
>>> get_letter_grade(89)
'B'
>>> get_letter_grade(79)
'C'
>>> get_letter_grade(69)
'D'
>>> get_letter_grade(59)
'F'
>>>
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.