Write a program to find the largest of two numbers in python with various method.

 def if_else(a,b):

    if a==b:

        return "Equal"

    if a>b:

        return a

    else:

        return b

def nested_if_else(a,b):

    if a>b:

        return a

    elif b>a:

        return b

    else:

        return "Equal"

def ternary_operator(a,b):

    if a==b:

        return "Equal"

    else:

        return(a if a>b else b)

def using_method(a,b):

    return(max(a,b))

while True:

    print()

    print("\t\t\t\tFinding Greatest Of Two Number\t\n")

    print("\t1.Greatest of Two Number Using if Else\t\t2.Greatest of two Number Using Nested if else")

    print("\n\t\t\t\t\t\t5.Exit\n")

    print("\t3.Greatest of Two Number Using Method\t\t4.Greatest of two Number Using Ternary Operator")

    choice=int(input("\n\tEnter Your Choice:"))

    if choice==1:

        num1=int(input("\n\tEnter The First Number:"))

        num2=int(input("\n\tEnter The Second Number"))

        greatest=if_else(num1,num2)

        print("\n\tGreatest Number of {0} and {1} is =".format(num1,num2),greatest)

        input("\n\t")

    elif choice==2:

        num1=int(input("\n\tEnter The First Number:"))

        num2=int(input("\n\tEnter The Second Number"))

        greatest=nested_if_else(num1,num2)

        print("\n\tGreatest Number of {0} and {1} is =".format(num1,num2),greatest)

        input("\n\t")

    elif choice==3:

        num1=int(input("\n\tEnter The First Number:"))

        num2=int(input("\n\tEnter The Second Number"))

        greatest=using_method(num1,num2)

        print("\n\tGreatest Number of {0} and {1} is =".format(num1,num2),greatest)

        input("\n\t")

    elif choice==4:

        num1=int(input("\n\tEnter The First Number:"))

        num2=int(input("\n\tEnter The Second Number"))

        greatest=ternary_operator(num1,num2)

        print("\n\tGreatest Number of {0} and {1} is =".format(num1,num2),greatest)

        input("\n\t")

    elif choice==5:

        print("\n\t𝕋𝕙𝕒𝕟𝕜𝕤 𝔽𝕠𝕣 𝕌𝕤𝕚𝕟𝕘 𝕋𝕙𝕚𝕤 ℙ𝕣𝕠𝕘𝕣𝕒𝕞 ❤")

        input("\n\t𝓟𝓻𝓮𝓼𝓼 𝓔𝓷𝓽𝓮𝓻 𝓚𝓮𝔂 𝓣𝓸 𝓔𝔁𝓲𝓽")

        exit("\n\t")

    else:

        print("\n\tOpps! You Have Entered Wrong Option! Try Again")

        


Post a Comment

0 Comments