Ternary Operator for Pass/Fail Grading

Easy ⏱ 8 min 86% acceptance ★★★★☆ 4.2
Write a function grade_label(score) that returns "Pass" if score >= 40, else "Fail", implemented as a single-line conditional (ternary) expression rather than a multi-line if/else statement.

Examples

Example 1
Input
grade_label(55)
Output
'Pass'
Explanation

55 >= 40.

Example 2
Input
grade_label(39)
Output
'Fail'
Explanation

39 < 40.

Constraints

  • score is an int from 0 to 100.

Topics

Operatorsconditional expressions

Companies

InfosysWiproCapgemini

Hints

Hint 1

Python's ternary syntax: `value_if_true if condition else value_if_false`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.