21
loading...
This website collects cookies to deliver better user experience
your_age = input('Enter your age to check if you are eligible to legally drive or not:')
if int(your_age) >= 18:
driving_permit = “Yes, you can drive!”
else:
driving_permit = “Sorry, you can’t drive yet!”
print(f"The Result - {driving_permit}")
Enter your age to check if you are eligible to legally drive or not: 20
The Result - Yes, you can drive!
your_age = input('Enter your age to check if you are eligible to legally drive or not:')
driving_permit = “Yes, you can drive!” if int(your_age) >= 18 else “Sorry, you can’t drive yet!”
print(f"The Result - {driving_permit}")
# A code snippet to demonstrate the Python ternary operator
# Finding the greatest of 2 numbers
x, y = 20, 40
max = x if x > y else y
print(max )
40
# A simple program to demonstrate Python ternary operator with Tuples
x, y = 20, 40
print( (y, x) [x > y] )
40
# A simple program to demonstrate Python ternary operator with Dictionary
x, y = 20, 40
print({True: x, False: y} [x > y])
40
# A simple program to demonstrate Python ternary operator with Lambda
x, y = 20, 40
print((lambda: y, lambda: x)[x > y]())
40