Bird
0
0

You have a variable score. Write an if-elif-else block that prints "Fail" if score is below 50, "Pass" if score is between 50 and 75 inclusive, and "Excellent" if above 75. Which script is correct?

hard🚀 Application Q9 of 15
Bash Scripting - Conditionals
You have a variable score. Write an if-elif-else block that prints "Fail" if score is below 50, "Pass" if score is between 50 and 75 inclusive, and "Excellent" if above 75. Which script is correct?
Aif [ $score -lt 50 ]; then echo "Fail" elif [ $score -le 75 ]; then echo "Pass" else echo "Excellent" fi
Bif [ $score -le 50 ]; then echo "Fail" elif [ $score -lt 75 ]; then echo "Pass" else echo "Excellent" fi
Cif [ $score -lt 50 ]; then echo "Fail" elif [ $score -lt 75 ]; then echo "Pass" else echo "Excellent" fi
Dif [ $score -le 50 ]; then echo "Fail" elif [ $score -le 75 ]; then echo "Pass" else echo "Excellent" fi
Step-by-Step Solution
Solution:
  1. Step 1: Fail condition

    Score below 50 means less than 50 (-lt 50).
  2. Step 2: Pass condition

    Between 50 and 75 inclusive means score greater or equal 50 and less or equal 75. Since fail covers below 50, just check less or equal 75 (-le 75).
  3. Step 3: Else is Excellent

    Scores above 75.
  4. Final Answer:

    if [ $score -lt 50 ]; then echo "Fail" elif [ $score -le 75 ]; then echo "Pass" else echo "Excellent" fi -> Option A
  5. Quick Check:

    Correct numeric ranges = B [OK]
Quick Trick: Order conditions from lowest to highest [OK]
Common Mistakes:
MISTAKES
  • Using -le instead of -lt for fail
  • Overlapping conditions
  • Missing then keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes