# 1.
Write a program to find the square root of a number
s=int(input("Enter square number:"))
sr=s**0.5
print("the square root of",s,"is:",sr)
# 2.Write a program to find the area of Rectangle.
l=int(input("Enter lenght of rectangle:"))
b=int(input("Enter breadth of rectangle:"))
area=l*b
print("Area of rectangle:",area)
# 3. Write a program to calculate area and perimeter of the square.
side=int(input("Enter the length of the side of the square:"))
area=side*side
peri=side*4
print("Area of square:",area)
print("Perimeter of square:",peri)
# 4. Write a program to check whether a number is even or odd.
n=int(input("Enter the number:"))
if(n%2)==0:
print(n,"is even number")
else:
print(n,"is odd number")
# 5.Write a program to check the largest number among the three numbers.
first=int(input("Enter the first number:"))
second=int(input("Enter the second number:"))
third=int(input("Enter the third number:"))
if(first>second) and (first>third):
print("First number",first,"is largest.")
elif(second>first) and (second>third):
print("Second number",second,"is largest.")
else:
print("Third number",third,"is largest.")
# 6. Write a Python program to print Fibonacci series.
n_terms=int(input("Enter the number of terms you want in the fibonacci
series:"))
n1=0
n2=1
c=0
while c < n_terms:
print(n1)
nt=n1+n2
n1=n2
n2=nt
c+=1
# 7 Write a Python program to calculate factorial of a number
n=int(input("Enter the number:"))
f=1
print("factorial of :",n)
while n>=1:
f=f*n
n=n-1
print(f)
# 8 Write a Python program to get the largest number from a list.
l=[1,2,3,4,5]
print("Largest number in list :",max(l))
OR
l=[1,2,3,4,5]
max_num=0
for i in l:
max_num=i
print("Largest number in list :",max_num)
""" 9 Write a Python program to create a set, add member(s) in a set and
remove one item from set"""
s=set()
s.add("apple")
s.add("banana")
s.add("cherry")
print("The original set is:",s)
s.remove("banana")
print("The modified set is:",s)
"""10 Write a Python script to concatenate following dictionaries to create a
new one. a. Sample Dictionary: b. dic1 = {1:10, 2:20} c. dic2 = {3:30, 4:40} d.
dic3 = {5:50,6:60}"""
dic1 = {1:10, 2:20}
dic2 = {3:30, 4:40}
dic3 = {5:50,6:60}
dic={}
for x in (dic1,dic2,dic3):
dic.update(x)
print(dic)
"""11 Write a Python function that accepts a string and calculate the number
of upper case letters and lower case letters"""
def uplo(s):
u=0
l=0
for n in s:
if(n.islower()):
l=l+1
elif(n.isupper()):
u=u+1
print("upper letter in string =",u)
print("lower letter in string =",l)
s=input("Enter the string:")
uplo(s)
"""12 Write a Python function that takes a number as a parameter and check
the number is prime or not"""
def prime(no):
if(no%2==0):
print("Number is not prime")
else:
print("Number is prime")
no=int(input("Enter a number:"))
prime(no)
"""13 Write a Python program that will calculate area and circumference
of circle using inbuilt Math Module"""
import math
def cp(radius):
area=math.pi*radius**2
circumference=2*math.pi*radius
return area,circumference
radius=int(input("Enter the radius of circle:"))
area,circumference=cp(radius)
print(" circle with radius:",radius)
print("Area of circle:",area)
print("Circumference of circle:",circumference)
"""14 Write a NumPy program to generate six random integers between 10
and 30"""
import numpy
random_int=numpy.random.randint(low=10,high=30,size=6)
print(random_int)
“””IN 14 IF IT SHOW ERROR MODULE NOT FOUND THEN OPEN CMD AND TYPE
Pip install numpy AND PRESS ENTER THEN INSTALLATION COMPLETE AND RUN
THE CODE”””
"""15 Create a class Employee with data members: name, department and
salary.
Create suitable methods for reading and printing employee information"""
class Employee:
def get(self):
self.name=input("Enter name:")
self.dept=input("Enter department:")
self.salary=int(input("Enter salary:"))
def put(self):
print("Name:",self.name)
print("Department:",self.dept)
print("Salary:",self.salary)
obj=Employee()
obj.get()
obj.put()
#16 Write a Python program to Check for ZeroDivisionError Exception
a=int(input("Enter a number:"))
b=int(input("Enter a number:"))
try:
c=a/b
except:
print("Zero Division Error")
else:
print("Division =",c)