Python Pratical MCA (A)
Python Pratical MCA (A)
Practical No :- 01
A. Develop Program to understand the decision control structures of python.
1)
amount=0
if units<=100:
amount=(units-100)*5
if units>200:
amount=500(units-100)*10
last_digit=num%10
if(last_digit%3==0):
else:
if per>90:
elif per<60:
Output:
Practical No :-02
Develop the program to understand the looping statement.
1)
str=input("Enter any word")
vowels=0
for i in str:
vowels=vowels+1
print(vowels)
2)
no=int(input("Enter number to find factorial"))
fact=1
for i in range(1,no+1):
fact=fact*i
sum=0
while(num>0):
reminder=num%10
num=num//10
sum=num+reminder
a = [1,5,8,6,2]
print("Largest element of list", max(a))
a = [1,5,8,6,2]
print("Smallest element of list", min(a))
Output:
# Creating Tuple
a=()
tup = tuple()
print(type(a))
print(type(tup))
lst=[]
a = int((input("Enter the size of tuple")))
for i in range(0,a):
b = (input("Add tuple element"))
lst.append(b)
tup = tuple(lst)
print(tup)
print(type(tup))
# Deleting Tuple
tup = (25,80,74,62,250)
print(tup)
print(type(tup))
print(" Maximum of Tuple",max(tup))
tup = (25,80,74,62,250)
print(tup)
print(" Minimum of Tuple",min(tup))
Output:
# Creating Dictionary
dic={}
my_dict={"Car1": "Audi", "Car2":"BMW",
"Car3":"Mercidies Benz","Car4":"Range Rover"}
print(type(dic))
print(my_dict)
print(type(my_dict))
import operator
#
d = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
#
s= sorted(d.items(), key=operator.itemgetter(1))
#
print('ascending order : ',s)
#
s1= dict( sorted(d.items(), key=operator.itemgetter(1),reverse=True))
#
print('descending order : ',s1)
car1_model={'Mercedes':1960}
car2_model={'Audi':1970}
car2_model.update(car1_model)
print(car2_model)
Output:
Practical No :- 04
Develop program to learn concept of functions scoping, recursion and
list ,mutability.
Function Scoping :-
1. # It is global function
x = "global"
def fun():
print("It is global scope inside :", x)
fun()
print("It is global scope outside :", x)
# It is local function
def myfunc():
x = ("It is local variable")
print(x)
myfunc()
Output:
2. # It is recursion Function
def factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = 3
print("The factorial of", num, "is", factorial(num))
Output:
Practical No :- 05
D. Develop program to understand object oriented programming using python.
class Raisoni:
def student(self):
print("All Raisoni Students")
class Education(MCA):
def division(self):
print(“Welcome")
e=Education()
e.student()
e.division()
Output:
Practical No :- 06
Develop programs for data structure algorithms using python.
1. Searching:-
#Linear Search
class linearsearch:
ele=[]
def get(self):
self.a=int(input("Enter no of element you want to insert"))
for i in range(0,self.a):
b=(input("Add element you want to search"))
self.ele.append(b)
def search(self):
c=int(input("Enter elemnt you want to search"))
for i in range(0,self.a):
if self.ele[i]==c:
break;
if i<self.a:
print("Element found at index : ",i+1)
else:
print("Not Found .....")
s=linearsearch()
s.get()
s.search()
Output:
2. Sorting :-
#Bubble Sort
class sort:
ele=[]
def get(self):
self.a=int(input("Enter no of element you want to insert"))
for i in range(0,self.a):
b=int((input("Add element you want to sort")))
self.ele.append(b)
print(self.ele)
def bsort(self):
for i in range(0,self.a):
for j in range(0,self.a-i-1):
if self.ele[j]>self.ele[j+1]:
temp=self.ele[j]
self.ele[j]=self.ele[j+1]
self.ele[j+1]=temp
def show(self):
print("Sorted list")
print(self.ele)
s=sort()
s.get()
s.bsort()
s.show()
Output:
Practical:-7
1.Develop program to learn GUI programming using Tkinter
base = Tk()
base.geometry("500x500")
base.title("registration form")
lb1.place(x=20, y=120)
en1= Entry(base)
en1.place(x=200, y=120)
lb3.place(x=19, y=160)
en3= Entry(base)
en3.place(x=200, y=160)
lb4.place(x=19, y=200)
en4= Entry(base)
en4.place(x=200, y=200)
lb5.place(x=5, y=240)
vars = IntVar()
cv = StringVar()
drplist.config(width=15)
cv.set("United States")
lb2.place(x=14,y=280)
drplist.place(x=200, y=275)
lb6.place(x=19, y=320)
en6.place(x=200, y=320)
lb7.place(x=21, y=360)
en7.place(x=200, y=360)
base.mainloop()
Output:
Practical:-9
Demonstrate the concept of exception handling programs For Try Catch And
Finally :
try:
x = n/m
except ZeroDivisionError:
finally:
Output:
Practical 10
E. Demonstrate implementation of the Anonymous Function Lambda.
A. Simple Lambda
x = lambda a, b, c : a + b + c
print(x(5, 6, 2))
Output:
B. Cube Lambda
# Python code to illustrate cube of a number
def cube(y):
return y*y*y
# defined function
print(cube(5))
print(lambda_cube(5))
OR
def cube(y):
return y*y*y
c = int(input("Enter the no: "))
Output:
Practical 11
Demonstrate implementation Mapping Functions over Sequences.
def mul(i):
return i * i
print(update)
mul_output = list(update)
print(mul_output)
Output:
Practical 12
Demonstrate implementation functional programming tools such as filter And
Reduce
a) **********
scores = [66, 90, 68, 59, 76, 60, 88, 74, 81, 65]
def is_A_student(score):
print(over_75)
b) *****************
dromes = ("demigod", "rewire", "madam", "freer", "anutforajaroftuna", "kiosk")
print(palindromes)
c) ***************
# Python 3
print(result)
d) ****************
from functools import reduce
Output:
Practical 13
Demonstrate the Module Creation, Module usage, Module Namespaces,Reloading
Modules, Module Packages, Data Hiding in Modules.
a) Module Creation:
def add(a, b):
result = a + b
import math as m
#from...import statement
Output: