0% found this document useful (0 votes)
2 views11 pages

Python All Pract

The document contains practical exercises for understanding various programming concepts in Python, including decision control structures, looping statements, data structures (lists, tuples, dictionaries), functions, object-oriented programming, and data structure algorithms. Each section provides code examples demonstrating the implementation of these concepts, such as calculating electricity bills, finding factorials, and performing linear search and sorting. The document serves as a comprehensive guide for learners to practice and apply Python programming skills.

Uploaded by

SAURABH SUPE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Python All Pract

The document contains practical exercises for understanding various programming concepts in Python, including decision control structures, looping statements, data structures (lists, tuples, dictionaries), functions, object-oriented programming, and data structure algorithms. Each section provides code examples demonstrating the implementation of these concepts, such as calculating electricity bills, finding factorials, and performing linear search and sorting. The document serves as a comprehensive guide for learners to practice and apply Python programming skills.

Uploaded by

SAURABH SUPE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical No :- 01

Develop Program to understand the decision control structures of


python.
1)

amount=0

units=int(input("Enter your units: "))

if units<=100:

print("No charges ")

if units>100 and units<=200:

amount=(units-100)*5

if units>200:

amount=500(units-100)*10

print("Electricity Bill =",amount)

2)

num=int(input("Enter any number :"))

last_digit=num%10

if(last_digit%3==0):

print("{} is divisible by 3".format(last_digit))

else:

print("{} is not divisible by 3".format(last_digit))


3)

per=int(input("Enter your percentage"))

if per>90:

print("The having A grade in examination")

elif per>80 and per<=90:

print("The having B grade in examination")

elif per>=60 and per<=80:

print("The having c grade in examination")

elif per<60:

print("The having D grade in examination")

Practical No :-02
Develop the program to understand the looping statement.
1)

str=input("Enter any word")

vowels=0

for i in str:

if( i=='a' or i=='e' or i=='i' or i=='o' or i=='u'or i=='A' or i=='E' or i=='I' or i=='O'
or i=='U'):

vowels=vowels+1

print("number of vowels are :")


print(vowels)

2)

no=int(input("Enter number to find factorial"))

fact=1

for i in range(1,no+1):

fact=fact*i

print("Factorial of that no is :",fact)

3)

num=int(input("Enter any number to find sum of digits : "))

sum=0

while(num>0):

reminder=num%10

num=num//10

sum=num+reminder

print("Sum of the digit is=%d",sum)

Practical No :-03
Develop programs to learn different types of structures(list,
dictionary, tuples) in python.
1)Write a program to demonstrate list sequence.
# Update the elements of the list

a = ['Ansh', 2, 35, 'code', 2.5]


print("Length of the list", len(a))
print("Before list",a)
a[0] = "ash"
print("After update list",a)

# Add new elements in to the list – append() , insert()

a = ['Ansh', 2, 35, 'code', 2.5]


print("list",a)
print("Length of the list", len(a))
[Link]("kash")
print("list",a)
print("Length of the list", len(a))
[Link](1,25)
print("list",a)
print("Length of the list", len(a))

# Removing elements from the list – remove() del

a = ['Ansh', 2, 35, 'code', 2.5]


print("list",a)
print("Length of the list", len(a))
b = [Link](1)
print("element deleted using pop()",b)
print("list",a)
[Link](35)
print("element deleted using remove()",a)
del a[1:3]
print("element deleted using del keyword",a)

# Find out length of the list

a = ['Ansh', 2, 35, 'code', 2.5]


print("list",a)
print("Length of the list", len(a))
# Find out maximum between list

a = [1,5,8,6,2]
print("Largest element of list", max(a))

# Find out minimum between list

a = [1,5,8,6,2]
print("Smallest element of list", min(a))

2) Write aprogram to demonstrate Tuple sequence.


# Write a program to demonstrate Tuple sequence.

# Creating Tuple

a=()
tup = tuple()
print(type(a))
print(type(tup))

# Read the elements of the tuple from the user

lst=[]
a = int((input("Enter the size of tuple")))
for i in range(0,a):
b = (input("Add tuple element"))
[Link](b)
tup = tuple(lst)
print(tup)
print(type(tup))

# Print the elements using slice operator.

tup=('apple', 'realme', 'redmi', 'moto')


print(tup[:])
print(tup[:3])
print(tup[3:])
print(tup[::-1])
print(tup[-1:])

# Deleting Tuple

tup = ('apple', 'realme', 'redmi', 'moto')


print("Tuple",tup)
del tup

# Find out length of the Tuple

tup = ('apple', 'realme', 'redmi', 'moto')


print(tup)
print(" Length of Tuple",len(tup))

# Find out maximum between list

tup = (25,80,74,62,250)
print(tup)
print(type(tup))
print(" Maximum of Tuple",max(tup))

# Find out minimum between list

tup = (25,80,74,62,250)
print(tup)
print(" Minimum of Tuple",min(tup))

3) Demonstrate the Dictionary.


# C. Demonstrate the dictionary

# 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))

# Sort dictionary by values(Ascending and descending)

import operator
#
d = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
#
s= sorted([Link](), key=[Link](1))
#
print('ascending order : ',s)
#
s1= dict( sorted([Link](), key=[Link](1),reverse=True))
#
print('descending order : ',s1)

# concatenate two dictionaries to create one

car1_model={'Mercedes':1960}
car2_model={'Audi':1970}
car2_model.update(car1_model)
print(car2_model)

# check whether the key exist or not

my_dict={"Car1": "Audi", "Car2":"BMW",


"Car3":"Mercidies Benz","Car4":"Range Rover"}
#
key = input("Enter the key you want to search:\n")
#
if key in my_dict.keys():
print("Present")
else:
print("Not Present")

# iterate the keys of dictionary

my_dict={"Car1": "Audi", "Car2":"BMW",


"Car3":"Mercidies Benz","Car4":"Range Rover"}
for x in my_dict:
print(x)

# iterate the values of dictionary

my_dict={"Car1": "Audi", "Car2":"BMW",


"Car3":"Mercidies Benz","Car4":"Range Rover"}
for x in my_dict.values():
print(x)

# iterate the items of dictionary

my_dict={"Car1": "Audi", "Car2":"BMW",


"Car3":"Mercidies Benz","Car4":"Range Rover"}
for x in my_dict.items():
print(x)

# remove the specific values

my_dict={"Car1": "Audi", "Car2":"BMW",


"Car3":"Mercidies Benz","Car4":"Range Rover"}
print("Original Dict \n",my_dict)
my_dict.pop('Car3')
print("Element removed using pop \n",my_dict)
del my_dict['Car2']
print("Element removed using del keyword \n",my_dict)
Practical No :- 04
Develop program to learn concept of functions scoping,
recursion and list ,mutability.
Function Scoping :-

# 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()

# 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))

Practical No :- 05
Develop program to understand object oriented programming
using python.

class saurabh:
def student(self):
print("Mr Saurabh Supe")
class Education(SaurabH):
def division(self):
print("MCA")

e=Education()
[Link]()
[Link]()

Practical No :- 06
Develop programs for data structure algorithms using python.
1) Searching:-
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"))
[Link](b)
def search(self):
c=int(input("Enter elemnt you want to search"))
for i in range(0,self.a):
if [Link][i]==c:
break;
if i<self.a:
print("Element found at index : ",i+1)
else:
print("Not Found .....")
s=linearsearch()
[Link]()
[Link]()

2) Sorting :-
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")))
[Link](b)
print([Link])
def bsort(self):
for i in range(0,self.a):
for j in range(0,self.a-i-1):
if [Link][j]>[Link][j+1]:
temp=[Link][j]
[Link][j]=[Link][j+1]
[Link][j+1]=temp
def show(self):
print("Sorted list")
print([Link])
s=sort()
[Link]()
[Link]()
[Link]()

You might also like