Solution Review: Pass or Fail

Let’s go over the solution of the challenge: Pass or Fail.

We'll cover the following

Task

In this challenge, you were provided the final percentage a student had at the end of the semester. You had to write a program that would determine if the student passed or failed. If the percentage was greater than or equal to 60 while also being greater than the average class percentage, the student passed, and if it was less than 60, the student failed.

Solution

Let’s go over the solution step-by-step.

  • The first thing you had to figure out was that this problem is a conditional problem and would require an if-else expression.

  • Next, you had to figure out what the conditions were. The first condition is that the student gets a percentage that is greater than or equal to 60 that is within 5 points of the class average. In this case, you would print pass.

if (percentage >= 60 && percentage > (average - 5)){
  print("pass");
}
  • Finally, the last step required you to figure out the default condition, which was that the student gets a percentage which is less than 60. In this case, you would print fail.
else{
  print("fail");
}

You can find the complete solution below:

You were required to write the code given from line 10 to line 14.

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy