Python If Condition Programs | Set 5

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

Question: 21

Write a python script to take input for three number check and print the largest number? (Method:2)

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
    m=a
else:
    if(b>c):
        m=b
    else:
        m=c
print("max no = ",m)

Using elif

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
    m=a
elif(b>c):
    m=b
else:
    m=c
print("max no = ",m)

Output:

Enter 1st no 25
Enter 2nd no 63
Enter 3rd no 68
max no = 68
>>>

Question: 22

Write a python script to take input for three number check and print the largest number? (Method:3)

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
m=a
if(b>m):
    m=b
if(c>m):
    m=c
print("max no = ",m)

Output:

Enter 1st no 25
Enter 2nd no 98
Enter 3rd no 5
max no = 98
>>>

Question: 23

Write a python script to take input for three number check and print the lowest number? (Method:1)

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a<b and a<c):
    print("Min no = ",a)
else:
    if(b<c):
        print("Min no = ",b)
    else:
        print("Min no = ",c)

Using elif

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a<b and a<c):
    print("Min no = ",a)
elif(b<c):
    print("Min no = ",b)
else:
    print("Min no = ",c)

Output:

Enter 1st no 25
Enter 2nd no 65
Enter 3rd no 14
Min no = 14
>>>

Question: 24

Write a python script to take input for three number check and print the lowest number? (Method:2)

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a<b and a<c):
    m=a
else:
    if(b<c):
        m=b
    else:
        m=c
print("Min no = ",m)

Using elif

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a<b and a<c):
    m=a
elif(b<c):
    m=b
else:
    m=c
print("Min no = ",m)

Output:

Enter 1st no 56
Enter 2nd no 32
Enter 3rd no 47
Min no = 32
>>>

Question: 24

Write a python script to take input for three number check and print the lowest number? (Method:3)

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
m=a
if(b<m):
    m=b
if(c<m):
    m=c
print("min no = ",m)

Output:

Enter 1st no 25
Enter 2nd no 6
Enter 3rd no 34
min no = 6
>>>

Question: 25

Write a python script to take input for three number check and print the following:
* Largest number
* Lowest number
* Difference between largest and lowest number

Sol:

a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
#max no
if(a>b and a>c):
    ma=a
else:
    if(b>c):
        ma=b
    else:
        ma=c
#min no
if(a<b and a<c):
    mi=a
else:
    if(b<c):
        mi=b
    else:
        mi=c
#diff
d=ma-mi
print("max no ",ma," min no ",mi," diff ",d)

Output:

Enter 1st no 25
Enter 2nd no 63
Enter 3rd no 2
max no 63 min no 2 diff 61
>>>

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

Python Basic Programming Tutorial

Python Introduction     Getting started in Python Programming      Python propgramming fundamentals     Python Operators    Python If Condition     Python for loop    Python range construct      Python While loop    break and continue statements     Different looping techniques     Python List     Python String     Python Functions    Python Inbuilt Functions     Python Recursion     Using Python Library     Python Tuples     Python Dictionary     Python Sets     Python Strings     Python Exception Handling     Python Data File Handling