Total Pageviews

Saturday, April 18, 2020

IF ELSE IN PYTHON

1. LARGER OF TWO NUMBERS - CLICK
2. POSITIVE NEGATIVE NUMBER CHECKING - CLICK
3. Python Program to Check if a Number is Odd or Even   CLICK
4.Python Program to Find the Largest Among Three Numbers CLICK
5. Python Program to Check Leap Year CLICK

1. Check Whether a Number is Positive or Negative

num = int(input("Enter a number: "))

if num >=
0:
    print("Positive Number")
else:
    print("Negative Number")

2. Check Whether a Number is Even or Odd

num = int(input("Enter a number: "))

if num %
2 == 0:
    print("Even Number")
else:
    print("Odd Number")

3. Find Larger of Two Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
    print("Largest =", a)
else:
    print("Largest =", b)

4. Check Voting Eligibility

age = int(input("Enter age: "))

if age >=
18:
    print("Eligible for Voting")
else:
    print("Not Eligible for Voting")

5. Check Whether a Number is Divisible by 5

num = int(input("Enter a number: "))

if num %
5 == 0:
    print("Divisible by 5")
else:
    print("Not Divisible by 5")

6. Find Smaller of Two Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a < b:
    print("Smaller =", a)
else:
    print("Smaller =", b)

7. Check Leap Year

year = int(input("Enter year: "))

if year %
4 == 0:
    print("Leap Year")
else:
    print("Not a Leap Year")

8. Check Pass or Fail

marks = int(input("Enter marks: "))

if marks >=
40:
    print("Pass")
else:
    print("Fail")

9. Check Whether Character is Vowel

ch = input("Enter a character: ")

if ch in "AEIOUaeiou":
    print("Vowel")
else:
    print("Consonant")

10. Find Greatest of Three Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a > b and a > c:
    print("Greatest =", a)
elif b > c:
    print("Greatest =", b)
else:
    print("Greatest =", c)

11. Check Whether Number is Zero

num = int(input("Enter a number: "))

if num ==
0:
    print("Zero")
else:
    print("Not Zero")

12. Check Driving Eligibility

age = int(input("Enter age: "))

if age >=
18:
    print("Eligible for Driving")
else:
    print("Not Eligible")

13. Find Absolute Value

num = int(input("Enter a number: "))

if num <
0:
    num = -num

print("Absolute Value =", num)

14. Check Number is Multiple of 10

num = int(input("Enter a number: "))

if num %
10 == 0:
    print("Multiple of 10")
else:
    print("Not a Multiple of 10")

15. Check Whether Number is Three-Digit

num = int(input("Enter a number: "))

if
100 <= num <= 999:
    print("Three-Digit Number")
else:
    print("Not a Three-Digit Number")

16. Calculate Grade

marks = int(input("Enter marks: "))

if marks >=
90:
    print("Grade A")
elif marks >=
75:
    print("Grade B")
elif marks >=
50:
    print("Grade C")
else:
    print("Grade D")

17. Check Whether a Number is Divisible by 2 and 3

num = int(input("Enter a number: "))

if num %
2 == 0 and num % 3 == 0:
    print("Divisible by 2 and 3")
else:
    print("Not Divisible by 2 and 3")

18. Find Largest Among Three Numbers

a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:
    print("Largest =", a)
elif b >= c:
    print("Largest =", b)
else:
    print("Largest =", c)

19. Check Whether a Character is Alphabet

ch = input("Enter a character: ")

if ('A' <= ch <= 'Z') or ('a' <= ch <= 'z'):
    print("Alphabet")
else:
    print("Not an Alphabet")

20. Calculate Electricity Bill

units = int(input("Enter units consumed: "))

if units <=
100:
    bill = units *
2
else:
    bill = units *
5

print("Electricity Bill =", bill)
 

21. Check Triangle Validity

a = int(input("Enter side 1: "))
b = int(input("Enter side 2: "))
c = int(input("Enter side 3: "))

if a + b > c:
    if b + c > a:
        if c + a > b:
            print("Valid Triangle")
        else:
            print("Invalid Triangle")
    else:
        print("Invalid Triangle")
else:
    print("Invalid Triangle")

22. Check Character Type

ch = input("Enter a character: ")

if 'A' <= ch <= 'Z' or 'a' <= ch <= 'z':
    if ch in "AEIOUaeiou":
        print("Vowel")
    else:
        print("Consonant")
else:
    print("Not an Alphabet")
 

 

No comments:

Post a Comment