Python Tutorial @ Home

# Python If Condition Programs | Set 8

### Set 1Set 2Set 3Set 4Set 5Set 6Set 7Set 8Set 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")
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")
```

Output:

1. Sum of two numbers
2. Square of a number
3. Product of 3 numbers
4. Max of 3 numbers
Enter 1st no 10
Enter 2nd no 20
Sum = 30
>>>

1. Sum of two numbers
2. Square of a number
3. Product of 3 numbers
4. Max of 3 numbers
Enter 1st no 95
Enter 2nd no 68
Enter 3rd no 7
Max no = 95
>>>

Question:

Write a python script for the following:

1. cube of a no
2. sum of 3 nos
3. diff between 2 nos
4. min of 3 nos

Sol:

```print("1. Cube of a numbers")
print("2. Sum of 3 numbers")
print("3. Difference between 2 numbers")
print("4. Min of 3 numbers")
if(ch==1):
a=int(input("Enter any no "))
c=a*a*a
print("Cube = ",c)
elif(ch==2):
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
d=a+b+c
print("Sum = ",b)
elif(ch==3):
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
if(a>b):
d=a-b
else:
d=b-a
print("Difference = ",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("Min no = ",d)
else:
print("Invalid choice")
```

Output:

1. Cube of a numbers
2. Sum of 3 numbers
3. Difference between 2 numbers
4. Min of 3 numbers
Enter any no 5
Cube = 125
>>>

1. Cube of a numbers
2. Sum of 3 numbers
3. Difference between 2 numbers
4. Min of 3 numbers
Enter 1st no 2
Enter 2nd no 3
Enter 3rd no 6
Sum = 3
>>>

1. Cube of a numbers
2. Sum of 3 numbers
3. Difference between 2 numbers
4. Min of 3 numbers