In Python language ternary operator is not present. But we can use if else in place of ternary operator here. The syntax is as:
value1 if condition else value2
The simple script to show the usage is as given below:
x=int(input("enter the number"))
y=int(input("enter second number"))
z= x if x>0 else y
print(z)
Problem1: Write a simple script to print the greatest number among two numbers entered by the user.
x=int(input("Enter first number "))
y=int(input("Enter second number "))
print("The greatest number is",x if x>y else y)
value1 if condition else value2
The simple script to show the usage is as given below:
x=int(input("enter the number"))
y=int(input("enter second number"))
z= x if x>0 else y
print(z)
Problem1: Write a simple script to print the greatest number among two numbers entered by the user.
x=int(input("Enter first number "))
y=int(input("Enter second number "))
print("The greatest number is",x if x>y else y)