0% found this document useful (0 votes)
135 views17 pages

PYTHON Programming

This document contains a Python programming practical file submitted by a student named DAKSH to their professor Dr. P.K. Gupta. It includes a certificate signed by the professor, an acknowledgement by the student, and a contents page listing 10 programs completed with their corresponding dates and signatures. The file appears to document the practical work done by the student in learning Python programming as part of their BCA degree.

Uploaded by

datob38982
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
135 views17 pages

PYTHON Programming

This document contains a Python programming practical file submitted by a student named DAKSH to their professor Dr. P.K. Gupta. It includes a certificate signed by the professor, an acknowledgement by the student, and a contents page listing 10 programs completed with their corresponding dates and signatures. The file appears to document the practical work done by the student in learning Python programming as part of their BCA degree.

Uploaded by

datob38982
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 17

PYTHON PROGRAMMING PRACTICAL FILE

PYTHON Programming
Practical File

Submitted To: Submitted By:


Dr. P.K. Gupta Name: DAKSH
Professor (python) Roll No: 03625502021
BCA-II year, IInd shift

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

CERTIFICATE

This is to certify that python Programming Practical File being submitted is a bonafide work
done by DAKSH Student of BCA 3rd Sem 2nd shift in partial fulfilment of the award of the
BCA degree.
He has worked under my guidance and supervision and has fulfilled the requirements of the
file that has been reached the requisite standards.

Date: 5TH January, 2023

Dr. P.K. Gupta


( Professor (python))

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

ACKNOWLEDGEMENT

I, DAKSH , the student of BCA 3rd Sem, am extremely grateful to JIMS college for the
confidence bestowed in me and entrusting my Practical file of python Programming.

At this juncture I feel deeply honoured in expressing my sincere thanks to my faculty,


Dr. P.K. Gupta for his valuable inputs, her guidance, encouragement and whole-hearted
cooperation and constructive criticism throughout the preparation of this practical file.

I take this opportunity to thank all the lab assistants, coordinators who have directly or
indirectly without which this file would not have been possible. Lastly but not the least I place
a deep sense of gratitude to my family members and my friends who have been constant
source of inspiration during the preparation of this Practical file

Student Name:
DAKSH
Date: 5TH January, 2022

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

CONTENTS
S Programs Date Signature
no.
1 WAP to enter 2 integers, 2 floating numbers and 22-Sep-
perform various arithmetic operations on them. 2022
WAP to check whether a number is an Armstrong
number or not.
2 WAP to check whether a number is an Armstrong 29-Sep-
number or not. 2022
3 WAP to print sum of all prime numbers between 5-Oct-
2 ranges. 2022
4 WAP to swap 2 strings 16-Oct-
2022
5 Write a menu driven program to accept 2 strings 22-Oct-
and perform the various functions using user 2022
defined functions.
6 WAP to find smallest and largest number in a 30-Oct-
string 202
7 Create a dictionary whose keys are month names 3-Nov-
and whose values are the days in corresponding 2022
month. · Ask user to enter a month name and
use dictionary to tell them how many days are
there in the month. · Print out all keys in
alphabetically order · Print out key value pair
sorted by number of days in each month.
8 Make a list of first 10 letters of alphabet, then 20-Nov-
use the slicing to do the following operations: · 2022
Print the first 3 letters of list. · Print any 3 letters
from middle of list · Print the letter from any
particular index to the end of list.
9 WAP that scans an email index and forms a tuple 29-Nov-
of username and domain. 202
10 WAP that uses a user defined function that 9-Dec-
accepts name and gender and prefixes Mr./Mrs. 2022
On the basis of gender.

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q1-Write a program to enter two integers,two floating numbers and perform


all arithematic operations on them.
CODE:
n1 = int(input("Enter first integer number:"))
n2 = int(input("Enter second integer number:"))
print("Addition of integers:",n1+2)
print("Subtraction of integers:",n1-n2)
print("Multiplication of integers:",n1*n2)
print("Division of integers:",n1/n2)
print("Floor Division integers:",n1//n2)
print("Modulus of integers:",n1%n2)
print("Exponentiation of integers:",n1**n2)

n1 = float(input("Enter first floating number:"))


n2 = float(input("Enter second floating number:"))
print("Addition of floating numbers:",a1+a2)
print("Subtraction of floating numbers:",a1-a2)
print("Multiplication of floating numbers:",a1*a2)
print("Division of floating numbers:",a1/a2)
print("Floor Division of floating numbers:",a1//a2)
print("Modulus of floating numbers",a1%a2)
print("Exponentiation of floating numbers",a1**a2)

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q2-Write a program to ckeck whether a number is armstrong number or not.


CODE:
number = int(input("Enter the number: "))
temp = number
num_sum=0
while temp!=0:
digi = temp%10
num_sum = num_sum+digi**3
temp = temp//10
if number == num_sum:
print(f"Entered number{number} is an armstrong")
else:
print(f"Entered number {number} is not an armstrong")

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q3-Write a program to print the sum of all the primes between two ranges.
CODE:
sum=0
for i in range(2,10):
for j in range(2,i//2+1):
if i%j==0:
sum=sum+j
print("sum of prime numbers: ",sum)

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q4-Write a program to swap two strings.


CODE:
print("-------Swaping two strings--------")
fname = "Ram "
lname = "Kumar"
print(fname,lname)
fname,lname = lname, fname
print(fname,lname)

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q5-write a menu driven program to accept two strings from the user and
perform the various functions using user defined functions.
CODE:
def performing_actions(str1,str2):
choice = 1
while choice != 4:
print('1 for concatenating strings')
print('2 for swaping strings')
print('3 for checking length of both strings')
print('4 for exit')
choice = int(input("Enter the option you want to choose: "))
if choice ==1:
print('Concatenating both strings: ',str1+' '+str2)
elif choice ==2:
a = str1; b = str2
a,b = b,a
print('Swaping both strings: ',a,b)
elif choice == 3:
print('Length of string1: ',len(str1),'and string2: ',len(str2))
elif choice == 4:
break
str1 = input("Enter first string: ")
str2 = input("Enter second string")
performing_actions(str1,str2)

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q6-Write a program to find the smallest and largest number in a list.


CODE:
l1 = []
num = int(input('How many elements in list: '))
for i in range(num):
numbers = int(input('Enter number '))
l1.append(numbers)
print("Maximum element in the list is :", max(l1),
"\nMinimum element in the list is :", min(l1))

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q7. Create a dictionary whose keys are month name and whose values are
number of days in the corresponding month:

(a) Ask the user to enter the month name and use the dictionary to tell how
many days are in month.

(b) Print out all of the keys in alphabetical order.

(c) Print out all of the month with 31 days.

(d) Print out the (key - value) pair sorted by the number of the days in each
month.
CODE:

a) month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july" :


31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}

mon = input("Enter the month name in short form :- ")

print("Number of days in ",mon,"=",month [ mon ])

OUTPUT:

b) month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july"


: 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}
lst = list ( month . keys() )
lst.sort()
print( lst )
OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

c) month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july"


: 31 , "aug" : 31 , "sept" : 30 , "oct" : 31 , "nov" : 30 , "dec" : 31}
print( "Month which have 31 days !!-- ")
for i in month :
if month [ i ] == 31 :
print( i )
OUTPUT:

d) month = { "jan" : 31 , "feb" : 28 , "march" : 31 , "april" : 30 , "may" : 31 , "june" : 30 , "july" : 31 , "aug" : 31 , "sept" : 30
, "oct" : 31 , "nov" : 30 , "dec" : 31}

print("Month according to number of days ---")

print("feb")

for i in month :

if month [ i ] == 30 :

print(i)

for i in month :

if month [ i ] == 31 :

OUTPUT:
:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q8-Write a Python program for the following:Make a list of first ten letters
of the alphabet, then using the slice operation do thefollowing
operations.A.Print the first three letters from the list.B.Print any three
letters from the middle.C.Print the letters from any particular index to the
end of the list.
CODE:
l1=['a','b','c','d','e','f',
'g','h','i','j']
print(l1[0:3])

OUTPUT:

b) l1=['a','b','c','d','e','f',
'g','h','i','j']
print(l1[2:5])

OUTPUT:

c) l1=['a','b','c','d','e','f',
'g','h','i','j']
print(l1[4:11])

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

Q9- write a program to sacn an email address and forms a tuple of user name
and domain.
CODE:
test_str = 'msgt@reekrock.com'
print("The original string is : " + str(test_str))
res = test_str[test_str.index('@') + 1 : ]
print("The extracted domain name : " + str(res))

OUTPUT:

Q10- Write a program that uses a user-defined function that accepts


name and gender (as M for Male, F for Female) and prefixes Mr/Ms on
the basis of the gender.
CODE:
ef prefix(name,gender):
if (gender == 'M' or gender == 'm'):
print("Hello, Mr.",name)
elif (gender == 'F' or gender == 'f'):
print("Hello, Ms.",name)
else:
print("Please enter only M or F in gender")
name = input("Enter your name: ")
gender = input("Enter your gender: M for Male, and F for Female: ")
prefix(name,gender)

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT


PYTHON PROGRAMMING PRACTICAL FILE

OUTPUT:

DAKSH 03625502021 BCA 2ND YEAR 2ND SHIFT

You might also like