IF Statement Based Programs
IF Statement Based Programs
if num > 0:
print(f"{num} is positive")
if num < 0:
print(f"{num} is negative")
if num == 0:
print("The number is zero")
if num % 5 == 0:
print(f"{num} is divisible by 5")
if char.isupper():
print(f"{char} is an uppercase letter")
if string == string[::-1]:
print(f"'{string}' is a palindrome")
if num1 == num2:
print("Both numbers are equal")
if num % 10 == 0:
print(f"{num} is a multiple of 10")
if len(string) == 0:
print("The string is empty")
if num % 2 != 0:
print(f"{num} is an odd number")
if year % 4 == 0:
if year % 100 != 0 or year % 400 == 0:
print(f"{year} is a leap year")
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(f"{num} is a prime number")
import math
if sqrt.is_integer():
print(f"{num} is a perfect square")
if substring in string:
print(f"The string '{string}' contains the substring
'{substring}'")
if num in numbers:
print(f"{num} is in the list")
16. Check if a Triangle is Equilateral
● Question: Write a program to check if a triangle is equilateral (all sides are equal).
if num_str == num_str[::-1]:
print(f"{num} is a palindrome")
if sorted(str1) == sorted(str2):
print(f"'{str1}' and '{str2}' are anagrams")
if string[0] in 'aeiou':
print(f"The string '{string}' starts with a vowel")
Solution:
year = int(input("Enter a year: "))
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
else:
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
Solution:
num = int(input("Enter a number: "))
Solution:
marks = int(input("Enter your marks: "))
Solution:
import math
if sqrt == int(sqrt):
print(f"{num} is a perfect square")
else:
print(f"{num} is not a perfect square")
Solution:
num = int(input("Enter a number: "))
if num > 1:
if num == 2 or num == 3:
print(f"{num} is a prime number")
elif num % 2 == 0 or num % 3 == 0:
print(f"{num} is not a prime number")
else:
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")
Solution:
a = int(input("Enter side 1: "))
b = int(input("Enter side 2: "))
c = int(input("Enter side 3: "))
if a == b == c:
print("The triangle is equilateral")
elif a == b or b == c or a == c:
print("The triangle is isosceles")
else:
print("The triangle is scalene")
Solution:
a = int(input("Enter side 1: "))
b = int(input("Enter side 2: "))
c = int(input("Enter side 3: "))
d = int(input("Enter side 4: "))
if a == b == c == d:
print("The quadrilateral is a square")
elif a == c and b == d:
print("The quadrilateral is a rectangle")
else:
print("The quadrilateral is some other type")
Solution:
x = int(input("Enter the x-coordinate: "))
y = int(input("Enter the y-coordinate: "))
Solution:
import math
discriminant = b**2 - 4 * a * c
if discriminant > 0:
root1 = (-b + math.sqrt(discriminant)) / (2 * a)
root2 = (-b - math.sqrt(discriminant)) / (2 * a)
print(f"The roots are real and different: {root1}, {root2}")
elif discriminant == 0:
root = -b / (2 * a)
print(f"The roots are real and the same: {root}")
else: