1.
Write a Program to check if a year is a leap year
A year is a leap year if it satisfies:
1. Rule 1: If the year is divisible by 400, it is a leap year.
→ e.g., 2000, 2400 are leap years.
2. Rule 2: If the year is divisible by 4 but not by 100, it is also a leap year.
→ e.g., 2016, 2024 are leap years.
3. Otherwise, it is not a leap year.
→ e.g., 1900, 2100 are not leap years (divisible by 100 but not by 400).
# Input from user
year = int(input("Enter a year: "))
# Check leap year conditions
if (year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
print(f"{year} is a Leap Year.")
else:
print(f"{year} is not a Leap Year.")
2. Wap to find roots of a quadratic equation.
from cmath import sqrt # for complex numbers
# Input coefficients
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
# Calculate discriminant
d = (b**2) - (4*a*c)
# Find two roots
root1 = (-b + sqrt(d)) / (2*a)
root2 = (-b - sqrt(d)) / (2*a)
# Display results
print(f"The roots of the quadratic equation are {root1} and
{root2}")
[Link] function to print Fibonacci series
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n - 1) + fibonacci(n - 2)
# Input number of terms
terms = int(input("Enter the number of terms: "))
for i in range(terms):
print(fibonacci(i), end=" ")
4. Program to display grade based on marks
marks = int(input("Enter your marks: "))
if marks >= 90:
print("Grade: O")
elif marks >= 80:
print("Grade: A")
elif marks >= 70:
print("Grade: B")
elif marks >= 60:
print("Grade: C")
elif marks >= 50:
print("Grade: D")
else:
print("Grade: F (Fail)")
5. Check if a number is divisible by both 3 and 5
num = int(input("Enter a number: "))
if num % 3 == 0 and num % 5 == 0:
print("Divisible by both 3 and 5.")
else:
print("Not divisible by both 3 and 5.")
6. ATM Withdrawal System
balance = 5000 # initial account balance
amount = int(input("Enter amount to withdraw: "))
if amount <= balance:
balance -= amount
print(f"Transaction successful! Remaining balance: ₹{balance}")
else:
print("Insufficient balance. Transaction failed.")
Q:
Write a Python program to calculate the electricity bill based on the number of units
consumed using an if–else statement.
Conditions:
For the first 100 units, the cost is ₹5 per unit.
For units above 100, the cost is ₹7 per unit.
units = int(input("Enter electricity units consumed: "))
if units <= 100:
bill = units * 5
else:
bill = (100 * 5) + (units - 100) * 7
print(f"Total Electricity Bill: ₹{bill}")
if- elif-else
[Link] greeting based on time of day
[Link] the season based on month number
Calculate discount based on purchase amount
leap year alternate pgm
year = int(input("Enter a year: "))
# Check if it is a century year first
if year % 100 == 0:
# For century years, it must be divisible by 400 to be a leap year
if year % 400 == 0:
print("its a Leap Year.")
else:
print("its not a Leap Year.")
else:
# For non-century years, it must be divisible by 4 to be a leap
year
if year % 4 == 0:
print("its a Leap Year.")
else:
print("its not a Leap Year.")
--------------------------------------------------------------