Part-A
1. Python script for checking the given year is leap year or not.
year = int(input("Enter a year: "))
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print("Leap Year")
else:
print("Not a Leap Year")
2. Python script to check if a number belongs to the Fibonacci Sequence.
num = int(input("Enter a number: "))
a=0
b =1
found = False
while a <= num:
if a == num:
found = True
break
c=a+b
a=b
b=c
if found:
print("Number belongs to Fibonacci sequence")
else:
print("Number does not belong to Fibonacci sequence")
3. Python script to solve Quadratic Equations.
import cmath
a = float(input('Enter the value of a: '))
b = float(input('Enter the value of b: '))
c = float(input('Enter the value of c: '))
# calculate the discriminant
d = (b ** 2) - (4 * a * c)
# find two solutions
sol1 = (-b + [Link](d)) / (2 * a)
sol2 = (-b - [Link](d)) / (2 * a)
print('The solution are {0} and {1}'.format(sol1, sol2))
4. Python script to display all numbers which are divisible by 7 but are not a
multiple of 5, between given range X and Y.
x = int(input("Enter starting range: "))
y = int(input("Enter ending range: "))
for i in range(x, y+1):
if i % 7 == 0 and i % 5 != 0:
print(i, end=" ")
5. Python script to display Multiplication Tables.
num = int(input("Enter a number: "))
for i in range(1, 11):
print(num, "x", i, "=", num*i)
6. Python script to create a calculator program.
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("[Link] [Link] [Link] [Link]")
choice = int(input("Enter choice: "))
if choice == 1:
print(a + b)
elif choice == 2:
print(a - b)
elif choice == 3:
print(a * b)
elif choice == 4:
print(a / b)
else:
print("Invalid choice")
7. Explore String Functions.
s = "Python Programming"
print([Link]())
print([Link]())
print([Link]())
print([Link]("Pro"))
print([Link]("Python", "Java"))
print(len(s))
8. Implementation of python script that takes a list of words and returns the length
of the longest one.
words = input("Enter words separated by space: ").split()
longest = max(words, key=len)
print("Longest word:", longest)
print("Length:", len(longest))
9. Python script handle multiple errors with one except statement.
try:
a = int(input("Enter a number: "))
b = int(input("Enter another number: "))
print(a / b)
except (ZeroDivisionError, ValueError):
print("Error: Invalid input or division by zero")
10. Python script to check whether password is valid or not. Conditions for a valid
password are: • Should have at least one number.
• Should have at least one uppercase and one lowercase character.
• Should have at least one special symbol.
• Should be between 6 to 20 characters long.
import re
password = input("Enter password: ")
if (len(password) >= 6 and len(password) <= 20 and
[Link]("[0-9]", password) and
[Link]("[A-Z]", password) and
[Link]("[a-z]", password) and
[Link]("[@#$%^&*!]", password)):
print("Valid Password")
else:
print("Invalid Password")