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

Python Programming File Priyam

The document contains a series of Python programming practicals developed by Priyam, covering various topics such as list operations, string manipulations, mathematical calculations, and control structures. Each practical includes source code, input/output examples, and is organized by unit numbers. The practicals aim to enhance programming skills through hands-on exercises in Python.

Uploaded by

maniraj86710
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 views37 pages

Python Programming File Priyam

The document contains a series of Python programming practicals developed by Priyam, covering various topics such as list operations, string manipulations, mathematical calculations, and control structures. Each practical includes source code, input/output examples, and is organized by unit numbers. The practicals aim to enhance programming skills through hands-on exercises in Python.

Uploaded by

maniraj86710
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

Page 1

PRACTICAL 1:Write a Python program to find the union of two lists.


Source Code:
””Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 01”””
list1 = [1, 2, 3, 4]
list2 = [3, 4, 5, 6]
union_list = list(set(list1 + list2))
print("Union of two lists is:", union_list)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 2

PRACTICAL 2: Write a Python program to find the intersection of two lists.


Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03’’’’’’

list1 = [1, 2, 3, 4, 5]

list2 = [3, 4, 5, 6, 7]

intersection = list(set(list1) & set(list2))

print("Intersection of two lists is:", intersection)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 3

PRACTICAL 3: Write a program to show different string operations. (A)


Concatenation (B) Repetition (C) Slicing and Indexing
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 01”””
# Program to show different string operations
str1 = "Rungta"
str2 = "College"
# Concatenation
print("Concatenation:", str1 + " " + str2)
# Repetition
print("Repetition:", str1 * 3)
# Indexing
print("Indexing:")
print("First character:", str1[0])
print("Last character:", str1[-1])
# Slicing
print("Slicing:")
print("First three characters:", str1[0:3])
print("Last two characters:", str2[5:7])

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 4

PRACTICAL 4: Write a program Using for loop, print a table of Celsius/Fahrenheit


equivalences. Let c be the Celsius temperatures ranging from 0 to 100, for each value of
c, print the corresponding Fahrenheit temperature
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
# Program to print Celsius-Fahrenheit table
print("Celsius\tFahrenheit")
for C in range(0, 101):
F = (9/5) * C + 32
print(C, "\t\t", F)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 5

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 6

PRACTICAL 5: Write a program Using while loop, produce a table of sins, cosines and
tangents. Make a variable x in range from 0 to 10 in steps of 0.2. For each value of x,
print the value of sin(x), cos(x) and tan(x).

Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
import math

print(f"{'x':<6} {'sin(x)':<10} {'cos(x)':<10} {'tan(x)':<10}")

print("-"*40)

x=0.0
while x<=10.0:

s=[Link](x)
c=[Link](x)

t=[Link](x)

print(f"{x:<6.1f} {s:<10.2f} {c:<10.2f} {t:<10.2f}")

x+=0.2

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 7

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 8

PRACTICAL 6: Write a program that reads the integer value and prints- leap year
or—not a leap year.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
year = int(input("Enter a year: "))

if year % 4 == 0:
print(year, "is a Leap Year")

else:

print(year, "is not a Leap Year")

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 9

PRACTICAL 7: Write a program that takes a positive integer n and then produces n
lines of output shown as follows.
For example, enter a size: 5
*
**
***
****
*****
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
n=int(input("Enter any integer value : "))

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

print('*'*i)
i+=1

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 10

PRACTICAL 8: Write a program of infinite while loop and stop the program execution
by pressing ctrl +c.

Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
i=1

while i<=5:

print(i)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 11

PRACTICAL 9: Write a program function that takes an integer _n as input and


calculates the value of 1 +1/1!+1/2+1/3!+...+1/n.

Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
def series(num):

fact=1

X=0
for i in range(1,num+1):

fact=fact*i

X=X+1/fact

i+=1

print(X)

series(5)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 12

PRACTICAL 10: Write a program of a function that takes an integer input and
calculates the factorial of that number.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 04”””
def fact(num):

fact=1

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

fact=fact*i

i+=1

print(f"Factorial of {num}! = {fact}")


fact(5)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 13

PRACTICAL 11: Write a program function that takes a string input and checks if it's a
palindrome or not.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 04”””
def check_palindrome(s):
# Convert string to lowercase and remove spaces
s = [Link]().replace(" ", "")
# Check if string is equal to its reverse
if s == s[::-1]:
return "Palindrome"
else:
return "Not a Palindrome"
# Input from user
text = input("Enter a string: ")
# Function call
result = check_palindrome(text)
# Output
print(result)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 14

PRACTICAL 12: Write a program list function to convert a string into a list, as in list
(abc) gives [a, b, c].
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
a_string=input("Enter any string : ")

a_list=list(a_string)
print("The Entered string is : ",end="")

print(a_string)

print()

print("After converting the string into the list : ")

print(a_list)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 15

PRACTICAL 13: Write a program to generate Fibonacci series.


Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
n=int(input("Enter number of terms : "))

a=0

b=1

for i in range(10):

print(a,end=" ")

next_term=a+b

a=b
b=next_term

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 16

PRACTICAL 14: Write a program to check whether the input number is even or odd.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
num = int(input("Enter any number : "))

if num%2==0:

print(num," is even.")

else:

print(num," is odd.")

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 17

PRACTICAL 15: Write a program to compare three numbers and print the largest one.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
num1=int(input("Enter any number : "))

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

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

if num1>num2 and num1>num3:

print(num1," is the largest number.")


elif num2>num3:

print(num2," is the largest number.")

else:

print(num3," is the largest number.")

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 18

PRACTICAL 16: write a program to print factors of a given number.


Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 02”””
num=int(input("Enter any number : "))

print(f"Factors of {num} are : ")

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

if num%i==0:

print(i)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 19

PRACTICAL 17: Write a program method to calculate GCD of two numbers.


Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
import math
num1 = 48
num2 = 18
result = [Link](num1, num2)
print(f"The GCD of {num1} and {num2} is: {result}")

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 20

PRACTICAL 18: Write a program to show all the operations of the list.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
fruits=['Banana','apple','cauli-flower','lemon','orange','strawberry']

print(fruits)

# modying list by using index

fruits[2]='Coconut'

print("\nAfter modificatin list is : \n",fruits)


'''Adding element in a list'''

# by using append() adding element at the last

[Link]('Mango')

print("\nAfter appending a new element the list is : \n",fruits)

# by using insert(), insert element at any positin in a list

[Link](1,'Grapes')

print("\nAfter inserting a new element at index 1 new list is : \n",fruits)


'''Removing Element from a list'''

#by using del statment, deleting element from any index ,deleted element can't be further usable

del fruits[4]

print("\nAfter deleting a element at the index 4 new list is :\n",fruits)

# by using pop(), deleting element ,deleted item can be usable

popped_element=[Link]()

print("\nAfter popping out last item of the list new list is : \n",fruits)

print(f"Popped item is : {popped_element}")


# by using pop(index_value),deleting an item from any position of the list.

popped_element=[Link](1)

print("\nAfter popping out item at index 1 from the list : \n",fruits)


print(f"Popped item is : {popped_element}")
# removing an item by value (instead of index using direct it's value)

[Link]('orange')
GDRCST Guided by:
2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 21

print("\nAfter removing 'orange' from the list the new list is : \n")

print(fruits)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 22

PRACTICAL 19: Write a program to show difference between list and tuples.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
# 1. Creation

my_list = [1, 2, 3]

my_tuple = (1, 2, 3)

# 2. Changing a List (This works)

print("List before change:", my_list)


my_list[0] = 99

print("List after change:", my_list)

# 3. Changing a Tuple (This will cause an error)

print("\nTuple is : ",my_tuple)

print("Tuples cannot be changed once created.")

# my_tuple[0] = 99 <-- This line would crash the program

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 23

PRACTICAL 20: Write a program to create Stack Class and implement all its methods.
(Use Lists).
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
class Stack:

def __init__(self):

[Link] = []

# Push element into stack

def push(self, item):

[Link](item)
print(item, "pushed into stack")

# Pop element from stack


def pop(self):

if self.is_empty():

print("Stack is empty")

else:

print([Link](), "popped from stack")

# Display top element

def peek(self):

if self.is_empty():

print("Stack is empty")

else:

print("Top element is:", [Link][-1])

# Check if stack is empty

def is_empty(self):

return len([Link]) == 0

#Display stack

def display(self):

if self.is_empty():

print("Stack is empty")

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 24

else:

print("Stack elements are:", [Link])

# Main Program

s = Stack()

[Link](10)

[Link](20)

[Link](30)

[Link]()

[Link]()

[Link]()

[Link]()

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 25

PRACTICAL 21: Write a Program to create Queue Class and implement all its
method. (Use lists)
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
class Queue:

def __init__(self):

[Link] = [] # Insert element into queue

def enqueue(self, item):


[Link](item)

print(item, "inserted into queue")

# Delete element from queue

def dequeue(self):

if self.is_empty():

print("Queue is empty")

else:
item = [Link](0)

print(item, "deleted from queue")

# Display queue elements


def display(self):

if self.is_empty():

print("Queue is empty")

else:

print("Queue elements are:", [Link])


# Check front element

def front(self):

if self.is_empty():

print("Queue is empty")
else:

print("Front element is:", [Link][0]) # Check rear element


GDRCST Guided by:
2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 26

def rear(self):

if self.is_empty():

print("Queue is empty")

else:

print("Rear element is:", [Link][-1])


# Check if queue is empty

def is_empty(self):

return len([Link]) == 0

# Get size of queue

def size(self):

print("Size of queue is:", len([Link]))


# Main Program

q = Queue()
[Link](10)

[Link](20)

[Link](30)

[Link]()

[Link]()

[Link]()

[Link]()
[Link]()

[Link]()

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 27

PRACTICAL 22: Write a Program to implement linear and binary search on lists.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
# Linear Search

def linear_search(numbers, item):

for i in range(len(numbers)):

if numbers[i] == item:

return i

return -1

# Binary Search
def binary_search(numbers, item):

start = 0

end = len(numbers) - 1

while start <= end:

middle = (start + end) // 2

if numbers[middle] == item:

return middle
elif item > numbers[middle]:
start = middle + 1

else:

end = middle – 1

return -1

# Taking input from user

numbers = []
n = int(input("How many elements do you want to enter? "))

for i in range(n):

value = int(input("Enter number: "))


[Link](value)

item = int(input("Enter the element to search: "))


GDRCST Guided by:
2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 28

# Linear Search Call

position1 = linear_search(numbers, item)

if position1 != -1:

print("Element found at position", position1, "using Linear Search")

else:
print("Element not found using Linear Search")

# Sorting list for Binary Search

[Link]()

print("Sorted List:", numbers)

# Binary Search Call

position2 = binary_search(numbers, item)


if position2 != -1:

print("Element found at position", position2, "using Binary Search")


else:

print("Element not found using Binary Search")

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 29

PRACTICAL 23: Write a Program to sort a list using insertion sort and bubble sort.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
numbers = []
n = int(input("Enter how many elements you want: "))
for i in range(n):
value = int(input("Enter number: "))
[Link](value)
print("Original List:", numbers)
# Bubble Sort
bubble_list = [Link]()

for i in range(len(bubble_list)):
for j in range(0, len(bubble_list) - i - 1):
if bubble_list[j] > bubble_list[j + 1]:
temp = bubble_list[j]
bubble_list[j] = bubble_list[j + 1]
bubble_list[j + 1] = temp
print("List after Bubble Sort:", bubble_list)
# Insertion Sort
insertion_list = [Link]()
for i in range(1, len(insertion_list)):
current = insertion_list[i]
position = i - 1
while position >= 0 and insertion_list[position] > current:
insertion_list[position + 1] = insertion_list[position]
position = position - 1
insertion_list[position + 1] = current
print("List after Insertion Sort:", insertion_list)

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 30

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 31

PRACTICAL 24: Write a program to remove the "i" th occurrence of the given word
in a list where words repeat.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
def remove_ith_word(word_list, target_word, i):

count = 0

for index in range(len(word_list)):

if word_list[index] == target_word:

count += 1

if count == i:
word_list.pop(index)

return word_list

print(f"{i}-th occurrence of targeted word is not exists in list!")

return word_list

my_list = ['apple', 'banana', 'apple', 'cherry', 'apple', 'mango']

word = 'apple'

occurrence_to_remove = 2
print("Original List:", my_list)

result = remove_ith_word(my_list, word, occurrence_to_remove)

print("Updated List :", result)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 32

PRACTICAL 25: Write a program to count the occurrences of each word in a given
string sentence.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
def count_word_occurrences(sentence):

words = [Link]().split()
word_count = {}

for word in words:

if word in word_count:

word_count[word] += 1

else:

word_count[word] = 1

return word_count

my_sentence = "Apple banana apple cherry banana apple"


print("Sentence:", my_sentence)

result = count_word_occurrences(my_sentence)

print("Word Counts:", result)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 33

PRACTICAL 26: Write a program to check if a substring is present in a given string.


Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
String='Abcdefghi'

substring=input("Enter any substring : ")

if [Link]() in [Link]():

print(f"{substring} is present in {String}")

else:

print(f"{substring} is not present in {String}")

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 34

PRACTICAL 27: Write a program to map two lists into a dictionary.


Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
l1=['Name','Class','Address']

l2=['Nisha','BCA-IV','Chhattishgarh']

print("First list is : \n",l1)

print("Second list is : \n",l2)

print()

student=dict(zip(l1,l2))

print("A maped dictionary from the above two list : \n",student)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 35

PRACTICAL 28: Write a program to create a dictionary with key as first character
and value as words starting with that character.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
def group_words_by_first_char(sentence):
words = [Link]().split()
char_dict = {}
for word in words:
first_char = word[0]
if first_char in char_dict:
char_dict[first_char].append(word)
else:
char_dict[first_char] = [word]
return char_dict
my_sentence = "Apple banana avocado cherry berry mango"
print("Sentence:", my_sentence)
result = group_words_by_first_char(my_sentence)
print("\nResult Dictionary:")
print(result)

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 36

PRACTICAL 29: Write a program to find the length of a list using recursion.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 03”””
def find_length(my_list):

# 1. BASE CASE

# if list is empty then its length is 0.

if my_list == []:

return 0
# 2. RECURSIVE STEP

# we say : count one for me , and give me the length of rest of the list.

else:

rest_list = my_list[1:] # Pehle element ko chhor kar baaki saari list

return 1 + find_length(rest_list)

l1=[1,2,3,4,5]

print("length of the list : \n",l1," = " ,find_length(l1))

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum
Page 37

PRACTICAL 30: Write a program to create a class in which one method accepts a
string from the user and another prints it.
Source Code:
"""Path: C:\Users\LENOVO\OneDrive\Documents\Attachments\Desktop\PythonPracticals\[Link]
Developed By: Priyam Unit No. 04”””
class StringHandler:

def __init__(self):

self.user_string = ""

def accept_string(self):

self.user_string = input("Enter any string: ")

def print_string(self):
print("The entered string is:", self.user_string)

my_object = StringHandler()

my_object.accept_string()

my_object.print_string()

INPUT/OUTPUT:

GDRCST Guided by:


2025-26 BCA 4th Sem(A) Ms. Farhat Anjum

You might also like