0% found this document useful (0 votes)
2 views

Aman

This document outlines a practical assignment for a Bachelor of Computer Application course at Hemchand Yadav Vishwavidyalaya, detailing various programming tasks in Python. Each task includes a specific aim, coding examples, and expected outputs, covering topics such as leap year determination, pattern creation, factorial calculation, and data structure implementations like stacks and queues. The assignment is guided by Mrs. Jaspreet Kaur and submitted by Aman Tikaria for the session 2024-25.

Uploaded by

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

Aman

This document outlines a practical assignment for a Bachelor of Computer Application course at Hemchand Yadav Vishwavidyalaya, detailing various programming tasks in Python. Each task includes a specific aim, coding examples, and expected outputs, covering topics such as leap year determination, pattern creation, factorial calculation, and data structure implementations like stacks and queues. The assignment is guided by Mrs. Jaspreet Kaur and submitted by Aman Tikaria for the session 2024-25.

Uploaded by

amantikriha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

A Practical Assignment On “Programming In Python”

Bachelor of Computer Application -III Year


Hemchand Yadav Vishwavidyalaya, Durg (C.G)
SESSION: 2024-25

Guided By:- Submitted By:-


Mrs. Jaspreet Kaur Aman Tikaria
(Assistant Professor) Class:-BCA-III

Submitted To:
GD RUNGTA COLLEGE OF SCIENCE & TECHNOLOGY,
BHILAI (C.G)
Index
S.No Name Of Practical Page Date of Submission Remarks
No Experiment Date

Write A Program
1. That Reads An 3 26-07-2024 02-09-2024
Integer Value And
Prints—Leap Year
Or --Not A Leap
Year.
Write A Program
2. To Create The 4 26-07-2024 02-09-2024
Following Pattern.
*
**
**
****
*****
Write A Function
3. That Takes An 5 02-08-2024 02-09-2024
Integer Input And
Calculates The
Factorial Of That
Number.
Write A Function
4. That String Input 6 02-08-2024 02-09-2024
And Checks If It Is A
Palindrome Or Not.

1|Page
Write A Program To
5. Generate Fibonacci 7 09-08-2024 02-09-2024
Series.
Write A Program To
6. Check Whether The 8 09-08-2024 02-09-2024
Input Number Is
Even Or Odd.
Write A Program To
7. Compare Three 9 16-08-2024 02-09-2024
Numbers And Print
The Largest One.
Write A Function
8. That Takes An 10 19-08-2024 14-10-2024
Integer N As Input
And Calculates The
Value Of 1+1/1! +
1/2! +1/n!
Write A List
9. Function To 11 19-08-2024 14-10-2024
Convert A String
Into A List, As In List
(-abc) Gives[a, b, c].
Write A Program To
10. Print Factors Of A 12 26-08-2024 14-10-2024
Given Number.

Write A Method To
11. Calculate GCD Of 13 26-08-2024 14-10-2024
Two Numbers.

2|Page
Write Program To
12. Create Stack Class 14-16 02-09-2024 14-10-2024
And Implement All
Its Methods (Use
Lists).
Write A Program To
13. Create Queue Class 17-19 02-09-2024 14-10-2024
And Implement All
Its Methods. (Use
Lists)
Write A Program To
14. Implement Linear 20-24 07-10-2024 14-10-2024
And Binary Search
On Lists.
Write A Program To
15. Sort A List Using 25-29 21-10-2024 04-11-2024
Insertion Sort And
Bubble Sort And
Selection Sort.
Write A Program
16. That Takes A 30 09-12-2024 16-12-2024
Positive Integer
And Then Produces
N Lines Of Output
Shown As Follows.

3|Page
PRACTICAL NO:-01
AIM:- Write A Program That Reads An Integer Value And Prints—
Leap Year Or --Not A Leap Year.
CODING:-
a= int(input("Enter The Year:"))
if a%4==0:
print("It Is Leap Year")
else:
print("It Is Not Leap Year")
OUTPUT:-

3|Page
PRACTICAL NO:-02
AIM:- Write A Program To Create The Following Pattern.
For example enter a size: 5 -
*
**
**
****
*****
CODING:-
n=int(input("Enter The Number Of Size:- "))
for i in range(0,n):
for j in range(0,i+1):
print("*",end="")
print()
OUTPUT:-

4|Page
PRACTICAL NO:-03
AIM:- Write A Function That Takes An Integer Input And Calculates
The Factorial Of That Number.
CODING:-
fact=1
a=int(input("Enter The Number:-"))
for i in range(1,a+1):
fact=fact*i
print("Factorial Is:",fact)
OUTPUT:-

5|Page
PRACTICAL:-04
AIM:- Write A Function That String Input And Checks If It Is A
Palindrome Or Not.
CODING:-
def palindrom(string):
if(string == string[::-1]):
print("The String Is Palindrom")
else:
print("The String Is not Palindrom")
string=input("Enter String:")
palindrom(string)
OUTPUT:-

6|Page
PRACTICAL NO:-05
AIM:- Write A Program To Generate Fibonacci Series.
CODING:-
n1=0
n2=1
print(n1,n2,end=" ")
for i in range(2,10):
n3=n2+n1
print(n3,end=" ")
n1=n2
n2=n3
OUTPUT:-

7|Page
PRACTICAL NO:-06
AIM:-Write A Program To Check Whether The Input Number Is Even
Or Odd.
CODING:-
a=int(input("Enter Number:"))
if a%2==0:
print("It is Even Number")
else:
print("It is Odd Number")
OUTPUT:-

8|Page
PRACTICAL NO:-07
AIM:- Write A Program To Compare Three Numbers And Print The
Largest One.
CODING:-
l=int(input("Enter The First Number:-"))
m=int(input("Enter The Second Number:-"))
n=int(input("Enter The Third Number:-"))
if(l>m & m>n):
print(l,"is Largest Number")
elif(m>n):
print(m,"is Largest Number")
else:
print(n,"is Largest Number")
OUTPUT:-

9|Page
PRACTICAL NO:-08
AIM:- Write A Function That Takes An Integer N As Input And
Calculates The Value Of 1+1/1! + 1/2! + 1/n!
CODING:-
def fact_sum():
fact,sum=1,1
n=int(input("Enter A Number:- "))
for i in range(1,n+1):
fact=fact*i
sum=sum+(1/fact)
print(sum)
fact_sum()
OUTPUT:-

10 | P a g e
PRACTICAL NO:-09
AIM:-Write A List Function To Convert A String Into A List,As In List
(-abc) Gives [a, b, c].
CODING:-
def string_to_list(s):
if s.startswith('-'):
s = s[1:]
return list(s)
input_string = "-abc"
result = string_to_list (input_string)
print (result)
OUTPUT:-

11 | P a g e
PRACTICAL NO:-10
Aim:- Write A Program To Print Factors Of A Given Numbers.
CODING:-
def Print_Fact(x):
print("The Factors Are")
for i in range(1,x+1):
if x % i == 0:
print(i)
print("Factors Of A Number:-")
num = int(input("Enter The No:- "))
Print_Fact(num)
OUTPUT:-

12 | P a g e
PRACTICAL NO:-11
AIM:- Write A Method To Calculate GCD Of Two Numbers.
CODING:-
def hcf(a,b):
if(b == 0):
return a
else:
return hcf(b,a % b)
a=int(input("Enter The First no:"))
b=int(input("Enter The Second No:"))
print("The GCD Of",a,"and",b,"is:",end ="")
print(hcf(a,b))
OUTPUT:-

13 | P a g e
PRACTICAL NO:-12
AIM:- Write Program To Create Stack Class And Implement All Its
Methods(Use Lists).
CODING:-
def enqueue():
element = input("Enter The Number:-")
stack.append(element)
print("Elements Added The Stack")
def dequeue():
if not stack:
print("stack Is Empty")
else:
element=stack.dequeue()
print("Removal Element From Stack")
def display():
print(stack)
stack=[]
true=1
while true==1:
print("\nPass 1 to Add Element an Item in Stack \nPass 2
delete an element an item in stack \nPass 3 To Print Stack \nPass 4
to end the loop")
choice=int(input("enter your choice:- "))
if choice == 1:
enqueue()
14 | P a g e
if choice == 2:
dequeue()
if choice == 3:
display()
elif choice == 4:
true=2
else:
print("You Entered a wrong choice")
OUTPUT:-

15 | P a g e
16 | P a g e
PRACTICAL NO:-13
AIM:- Write A Program To Create Queue Class And Implement All
Its Methods.(Use Lists)
CODING:-
def a():
ele=input("Enter An Element= ")
queue.append(ele)
print("Element Added To Queue")
def b():
if not queue:
print("Queue Is Empty")
else:
ele=queue.p(0)
print("Removed Element")
def d():
print(queue)
queue=[]
t=1
while t == 1:
print("\n\nPress 1 To Add An Item In Queue \nPress 2 To Delete
An Item From Queue \nPress 3 To Print Queue\nPress 4 To End The
Loop")
c=int(input("Enter Your Choice= "))
if c == 1:
a()
17 | P a g e
elif c == 2:
b()
elif c == 3:
d()
elif c == 4:
t=2
else:
print("You Enterned Wrong Choice! Try Again")
OUTPUT:-

18 | P a g e
19 | P a g e
PRACTICAL NO:-14
AIM:- Write A Program To Implement Linear And Binary Search On
Lists.
CODING:-
def add_element( ):
element = int(input("Enter an element = "))
list.append(element)
print("Element Added to List")
def remove_element():
if not list :
print("list is Empty")
else :
k= int(input("Enter an element to remove from list = "))
list.remove(k)
print("Element Removed")
def display():
print(list)
def linear_search(list,n,x):
for i in range(0,n):
if(list[i]==x):
return i
return -1
def binary_search(list, x, low, high):
while low <= high:

20 | P a g e
mid = low + (high - low)//2
if list[mid] == x:
return mid
elif list[mid] < x:
low = mid + 1
else:
high = mid - 1
return-1
list =[ ]
true =1
while true==1 :
print("\n\nPress 1 to add an item in queue \nPress 2 to delete an
item from queue\nPress 3 to print queue\nPress 4 for linear
search\nPress 5 for binary search\nPress 6 to end the loop ")
choice = int(input("Enter your choice = "))
if choice ==1:
add_element()
elif choice==2:
remove_element()
elif choice==3:
display()
elif choice==4:
x=int(input("Enter a value to find ="))
n=len(list)

21 | P a g e
result=linear_search(list,n,x)
if(result==-1):
print("Element is not present in list")
else:
print("Element is present in list at index :- ",result)
elif choice==5:
x = int(input("Enter an element to find = "))
result = binary_search(list, x, 0, len(list)-1)
if (result==-1):
print("Element is not present in list",result)
else:
print("Element is present in list at index :- ",str(result))
elif choice==6:
true=2
else:
print("You Entered wrong choice! Try Again!!!")

22 | P a g e
OUTPUT:-

23 | P a g e
24 | P a g e
PRACTICAL NO:-15
AIM:- Write A Program To Sort A List Using Insertion Sort A List
Insertion Sort And Bubble Sort And Selection Sort.
CODING:-
def a_ele():
ele=int(input("Enter An Element= "))
list.append(ele)
print("Element Added To List")
def r_ele():
if not list:
print("List Is Empty")
else:
a=int(input("Enter An Element To Remove From List= "))
list.r(a)
print("Removed Element")
def d():
print(list)
def i_sort(list):
for step in range(1,len(list)):
k=list[step]
h=step-1
while(h >= 0) and (k < list[h]):
list[h+1]=list[h]
h=h-1

25 | P a g e
list[h+1]=k
def b_sort(list):
v=len(list)
for i in range(v-1):
for h in range(0,v-i-1):
if list[h] > list[h+1]:
list[h],list[h+1] = list[h+1],list[h]
def s_sort(list):
for i in range(len(list)):
min_i=i
for h in range(i+1,len(list)):
if list[min_i] > list[h]:
min_i=j
list[i],list[min_i] = list[min_i],list[i]
list=[]
t=1
while t == 1:
print("\n\nPress 1 To Add An Item In List\nPress 2 To Delete An
Item From List\nPress 3 To Print List\nPress 4 For Insertion
Sort\nPress 5 For Bubble Sort\nPress 6 For Selection Sort\nPress 7
To End The Loop")
c=int(input("Enter your Choice= "))
if c == 1:
a_ele()
elif c == 2:
26 | P a g e
r_ele()
elif c == 3:
d()
elif c == 4:
i_sort(list)
print("Sorted List Using Insertion Sort:- ")
print(list)
elif c == 5:
b_sort(list)
print("Sorted List Using Buuble Sort:- ")
for i in range(len(list)):
print("%d" %list[i],end=" ")
elif c == 6:
s_sort(list)
print("Sorted List Using Selection Sort")
for i in range(len(list)):
print("%d"%list[i],end=" ")
elif c == 7:
t=2
else:
print("You Entered Wrong Choice! Try Again!!!")

27 | P a g e
OUTPUT:-

28 | P a g e
29 | P a g e
PRACTICAL NO:-16
AIM:- Write A Program That Takes A Positive Integer And Then
Produces N Lines Of Output Shown As Follows.
CODING:-
def print_pat(n):
if n <= 0:
print("Please Enter A Positive Integer,")
return

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


print(f"line {i} : {'a' * i}")

try:
a = int(input("Enter A Positive Integer:"))
print_pat(a)
except ValueError:
print("Invalid Input! Please Enter An Interger.")
OUTPUT:-

30 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy