24
loading...
This website collects cookies to deliver better user experience
[value_if_true] if [expression] else [value_if_false]
_<expression 1>_ **if** _<condition>_ **else** _<expression 2>_
if-else
” conditions lets first write a program that prompts to enter student marks and returns either pass or fail based on the condition specified.marks = input('Enter the marks: ')
if int(marks) >= 35:
print("The result is Pass")
else:
print("The result is Fail")
Enter the marks: 55
The result is Pass
if-else
condition, let us try using ternary operators. if-else
condition. if condition:
value_if_true
else:
value_if_true
condition ? value_if_true : value_if_false
# Python program to demonstrate ternary operator
marks = input('Enter the marks: ')
print("The result is Pass" if int(marks)>=35 else "The result is Fail")
Enter the marks: 34
The result is Fail