When creating expressions with multiple operators, you can consult this official Python operator precedence table as a guide, in order to make sure that the operations will be performed in the order that you need. It is important to note this opening statement:
The following table summarizes the operator precedence in Python, from lowest precedence (least binding) to highest precedence (most binding).
That statement indicates that the operations listed at the bottom of the table will performed first, with the ones at the top performed last. Notice that parentheses are listed in the last row of the table, indicating that they can be used to control the order of operations in any expression.
Not sure if this is a difference in countries (and grading system) but it seems to me that for the task 2 there is a logic error in the correct result (I only got it right because I tried to do a false statement).
The task was to add a condition to check, if the gpa is correct.
The gpa condition was set, that you need a gpa of 2 or higher.
While (at least to my knowledge) talking from a “higher” gpa (in terms of a better gpa, which is the meaning here as a condition, because I am sure they do not want to have the worst students only to suceed) would be a lower number.
Afaik for the general gpa calculations, 1.0 should be the best and 6.0 the worst. So if we want only 2 gpa or better students to succeed, the statement has to be:
f credits >= 120 and gpa <= 2.0:
print("You meet the requirements to graduate!")
The exercise however wants this statement (and would deem the other as wrong):
f credits >= 120 and gpa >= 2.0:
print("You meet the requirements to graduate!")
For me, this is a clear logic error, unless the grading system is the other way around (1 worst, 6 best, like in Switzerland e.g.). Then however a GPA of 2.0 would not make sense to be a criteria for graduating, because it would mean an extremely bad result.
In my opinion (no matter which way you turn it) the results seems rather off (either saying the school is not very good and graduates everyone who can at least write their name right, or the check for the gpa is wrong).
if credits >= 120 and gpa >= 2.0:
is correct,
while if credits >= 120 and gpa >= 2:
isn’t.
Is this because, you have to add the decimal point, so that python understand that 2 is a floating point numer and it can only compare variables of the same class?
This part was very confusingly worded to me.
Firstly, I had an issue with the task being worded here:
Rewrite the if statement so that it checks to see if a student meets both requirements using an and statement.
If they do, return the string:
I was trying to make a return command work for some time, even trying to research how to make it work. It was good for problem solving but tacked on a needless 20 minutes of trying to figure it out myself. I caved eventually and looked at the “hint” which had the second condition in squared brackets. Ultimately, this combined with other countries using different scoring made it quite unclear? This isn’t the first case of a lesson using the word for a completely different statement, either. Just thought I’d make it known to watch the wording.