Python If Condition Programs | Set 9

Set 1    Set 2    Set 3    Set 4   Set 5  Set 6  Set 7  Set 8  Set 9

Question:

Write a python script for the following:

1. sum of 2 nos
2. square of number
3. product of 3 nos
4. max of 3 nos

Sol:

print("1. Sum of two numbers")
print("2. Square of a number")
print("3. Product of 3 numbers")
print("4. Max of 3 numbers")
ch=int(input("Enter your choice "))
if(ch==1):
    a=int(input("Enter 1st no "))
    b=int(input("Enter 2nd no "))
    c=a+b
    print("Sum = ",c)
elif(ch==2):
    a=int(input("Enter any no "))
    b=a*a
    print("Square = ",b)
elif(ch==3):
    a=int(input("Enter 1st no "))
    b=int(input("Enter 2nd no "))
    c=int(input("Enter 3rd no "))
    d=a*b*c
    print("Product = ",d)
elif(ch==4):
    a=int(input("Enter 1st no "))
    b=int(input("Enter 2nd no "))
    c=int(input("Enter 3rd no "))
    if(a>b and a>c):
        d=a
    elif(b>c):
        d=b
    else:
        d=c
    print("Max no = ",d)
else:
    print("Invalid choice")

Set 1    Set 2    Set 3    Set 4   Set 5  Set 6  Set 7  Set 8  Set 9