Python Conditional Statement Examples
Problem 1: Check if a number is Even or Odd
Example 1
a = int(input("Enter a number: "))
if a % 2 == 0:
print(a, "is a Even number")
else:
print(a, "is a Odd number") Problem 2: Check if a String is a Palindrome
Example 2
word = "madam"
if word == word[::-1]:
print("Palindrome")
else:
print("Not a Palindrome") Problem 3: Find the largest of three numbers
Example 3
a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
c = int(input("Enter 3rd number: "))
if a > b and a > c:
print(a, "is greatest")
elif b > c:
print(b, "is greatest")
else:
print(c, "is greatest") Problem 4: Check if character is Vowel or Consonant
Example 4
a = input("Enter a latter: ")
if a in "AEIOUaeiou":
print(a, "is an vowel")
else:
print(a, "is a consonant") Problem 5: ATM withdrawal Logic (withdrawal amount must be a multiple of 100 and You must have at least ₹500 in the account after withdrawal)
Example 5
a = 4000
b = int(input("Enter amount: "))
if b % 100 == 0:
if (a - b) >= 500:
a -= b
print(b, "rupee successfully withdrawal, Balance:", a)
else:
print("low balance", a)
else:
print("invalid withdrawal")