ESTO. 1885
Session: - 2024-2025
PRACTICAL FILE
PYTHON PROGRAMMING
Bachelor of Computer Applications
3rd Semester
Submitted By: - Submitted To: -
Nitin Parmar Mr. Vivek Jain
Roll No. - 73 SIQNAULE... 00000000000Acknowledgement
| would like to express my sincere gratitude to my PYTHON
Programming teacher, Mr. Vivek Jain, for his invaluable guidance
and unwavering support throughout the completion of this
project.
Additionally, | extend my heartfelt thanks to my parents and
friends who provided tremendous assistance in finalizing this
project within the given time constraints.
Lastly, | am grateful to all my supporters whose encouragement
and motivation inspired me to successfully accomplish the
project ahead of schedule.
Thank you all for your support and belief in my work.
DATE: 10/12/2024 Nitin Parmar
BCA 3rd SemesterINDEX
S.No Title Page| Teacher
No. | Signature
1 _| WAP to add two number in Python. 1
2 | WAP to print the average of four number. 2
3 | WAP to input a number check whether it is even or odd. 3
4 | WAP to input a number check whether it is positive, 4
negative or zero.
5 WAP to input a number print the sum of its digits. 5
6 | WAP to input a number check whether it is palindrome 6
number or not.
7 | WAP to input a number check whether it is Prime number | 7
or not.
8 | WAP to input a number print its factorial using functions. | 8
9 WAP to swap two values using a function. 9
10 | WAP to Demonstrate default argument in a function. 10
11 | WAP for selection sort. 1
12 WAP to multiple two matrix. 12
13 | WAP to Demonstrate tuple 13
14 | WAP to Demonstrate List and its methods (sort(), 14
append(), extend(), max(), mini), len()).
15 | WAP to Demonstrate dictionary and its method (len(), 15
clear(), get(), items(), keys(), values() )..
16 WAP to input Roll number , name and Marks of a class 16
and stores these details in a file called marks.txt.
17 | WAP to store information ina file. 17
18 | WAP to read a complete file line by line. 18Q.1 Write a program to add two number in Python.
Qutput
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")
sum = int(num1) + int(num2)
print(f"The sum of {num1} and {num2} is {sum}")
[aimee lan eed
Enter second number: 18
LPQ.2 Write a program to print the average of four
number.
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
numé = int(input("Enter fourth number: "))
average = (num1 + num2 + num3 + num4) / 4
print(f"The average of the four numbers is: {average}")
Output
first number: 20
ond number: 30
bap age Leet)
fourth number: 50
UeQ.3 Write a program to input a number check
whether it is even or odd.
num = int(input("Enter a number: "))
if num % 2 ==0:
print(f"{num} number is even")
else:
print(f"{num} number is odd")
Output
Enter a number: 2
2 number is even
ieee)
5 number is oddQ.4 Write a program to input a number check
whether it is positive, negative or zero.
num = int(input("Enter a number: "))
if num > 0:
print(f"{num} number is positive")
elif num < 0:
print(f"{num} number is negative")
else:
print(f"{num} number is zero")
Output
ee ee)
BO number is positive
Een
a mS
Sree
lO number is zeroQ.5 Write a program to input a number print the sum
of its digits.
Output
n=int(input("Enter the number:"))
sum=0
for digit in str(n):
sum=sum+int(digit)
print("Sum of digits",sum)
Se loo
STROSS CeeQ.6 Write a program to input a number check
whether it is palindrome number or not.
num = input("Enter a number: ")
if num == num[::-1]:
print(f"{num} is a palindrome number")
else:
print(f"{num} is not a palindrome number")
Output
Enter a number:
Cae neuen oeQ.7 Write a program to input a number check
whether it is Prime number or not.
Output
num = int(input("Enter the number to be checked: "))
flag =0
ifmum>1:
for i in range(2, int(num / 2):
if (num % i == 0):
flag=1
break
if flag == 1:
print(num , “is not a prime number")
else:
print(num , “is a prime number")
en mec mee cE
EC eC et
Enter the number to be checked: 8
eae smQ.8 Write a program to input a number print its
factorial using functions.
num = int(input("Enter the number:"))
factorial = 1
if num <0:
print("Sorry, factorial does not exist for negative
numbers")
elif num == 0:
print(""The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output
Laem es)
The factorial of 5 is 120Q.9 Write a program to swap two values using a
function.
Output
x= int(input("Enter the number:"))
y = int(input("Enter the number:"))
temp =x
xey
y=temp
print(‘The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
eae a
erm ML Ce)
eC ae a aS Ee)
Ua CeCe SU)Q.10 Write a program to Demonstrate default
argument in a function.
def showinfo( name, city = "Hyderabad" ):
print ("Name:", name)
print (""City:", city)
return
showinfo(name = "Ansh", city = "Delhi")
showinfo(name = "Shrey")
Output
rie
PU
Soy
A 1)
10Q.11 Write a program for selection sort.
def SelectionSort(array, n):
for i in range(n):
for k in range(i + 1, n):
if array[k] < arrayfj):
i=k
(array(i], array[j]) = (arrayfj], array[i])
data = [-2, 45, 0, 11, -9]
n= len(data)
SelectionSort(data, n)
print('Sorted Array in Ascending Order:')
print(data)
Output
Sorted Array in Ascending Order:
[-9, -2, 0, 11, 45]
uuQ.12 Write a program to multiple two matrix.
Output
matrix1 = [[1, 2],
(3, 4]]
matrix2 = [[5, 6],
(7, 8]
result = [[0, 0],
(0, o}]
for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
for k in range(len(matrix2)):
result[i][j] += matrix1[i][k] * matrix2[k][j]
print("Result Matrix:")
for row in result:
print(row)
Result Matrix
rr)
Cem)
2Q.13 Write a program to Demonstrate tuple.
tup=("hi","Python",2)
print(type(tup))
print(tup)
print(tup[1: ])
print(tup[0:1])
print(tup+tup)
print(tup*3)
Output
a ae ore ee)
2 aren)
13Q.14 Write a program to Demonstrate List and its
methods (sort(), append(), extend(), max(), min(), len()).
my_list = [10, 20, 5, 30, 15]
my_list.append(25)
print("After append(25):", my_list)
my_list.extend([40, 50])
print("After extend([40, 50]):", my_list)
my_list.sort()
print("After sort():", my_list)
max_value = max(my_list)
print("Maximum value:", max_value)
min_value = min(my_list)
print("Minimum value:", min_value)
length = len(my_list)
print("Length of the list:", length)
Output
After append(25): [10, 20
After extend([40. 50]): [10. 20. 5. 30. 15. 25, 40. 50]
After sort(): [5, 10. 15,
Maximum value: 50
PPOs Be ey
Length of the list: 8
14Q.15 Write a program to Demonstrate dictionary and
its method (len(), clear(), get(), items(), keys(), values()).
student_info = {"name": "Alice","age": 22,"grade":
"A","major": "Computer Science"}
print(student_info)
print(len(student_info))
print(student_info.get("name"))
print(student_info.items())
print(student_info.keys())
print(student_info.values())
student_info.clear()
Output
ree eC eg POR are iccmice tc
SC
dict_values([ ‘Ali
15Q.16 Write a program to input Roll number , name
and Marks of a class and stores these details in a file
called marks.txt.
def main():
with open('marks.txt', 'w') as file:
while True:
student_class = input("Enter Class: ")
if student_class.lower() == ‘exit’:
break
name = input("Enter Name: ")
roll_number = input("Enter Roll Number: ")
marks = input("Enter Marks: ")
file.write(f"{student_class},{name},{roll_number},{marks}\,
n")
main()
Output
16Q.17 Write a program to store information in a file.
info = input("Enter the information to store: ")
with open("info.txt", "w") as file:
file.write(info)
print("Information stored in file.")
Output
IiyeT USC) MEL ee ae
7Q.18 Write a program to read a complete file line by
line.
with open("‘info.txt", "r") as file:
for line in file:
print(line.strip())
Output
Hello, I am a BCA Student.
18