Ternary Operators
Ternary Operators
A ternary operator is a shorthand, one-line way of writing an if-else statement. Instead of writing multiple lines of code for a simple assignment, you can evaluate a condition inline.
Syntax: value_if_true if condition else value_if_false
Problem Statement
Write a Python program that takes a student's exam score. Use a ternary operator to assign "Pass" if the score is 50 or higher, or "Fail" if it is below 50. Then print the final status.
Expected Output :
Enter your exam score: 78
Status: Pass
Problem Statement
Write a Python program that takes an integer from the user and uses a ternary operator to assign either "Even" or "Odd" to a variable based on whether it is divisible by 2.
Expected Output:
Enter an integer: 7
The number is: Odd