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

Python Record Merged

This document is a practical record for the Programming in Python Lab for I Year BCA students at Arcot Sri Mahaalakshmi Women’s College. It includes various Python programming exercises covering topics such as variables, operators, conditional statements, loops, functions, recursion, arrays, strings, modules, lists, tuples, dictionaries, and file handling. The document serves as a certification of the practical work done by the students and includes sample code and outputs for each exercise.

Uploaded by

lavanya naren007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Python Record Merged

This document is a practical record for the Programming in Python Lab for I Year BCA students at Arcot Sri Mahaalakshmi Women’s College. It includes various Python programming exercises covering topics such as variables, operators, conditional statements, loops, functions, recursion, arrays, strings, modules, lists, tuples, dictionaries, and file handling. The document serves as a certification of the practical work done by the students and includes sample code and outputs for each exercise.

Uploaded by

lavanya naren007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

VILLAPAKKAM-632521.

Department Of Computer Application

PROGRAMMING IN PYTHON LAB

Practical Record
2023 – 2026

LAB

Name :

Register No :

Subject :
Department Of Computer Application
PROGRAMMING IN PYTHON LAB

This is certified to be Bonafide record of Practical work done by


Ms._________________________________ I Year BCA at Computer Lab in Arcot
Sri Mahaalakshmi Women’s College, Villapakkam, Arcot.

HEAD OF THE DEPARTMENT STAFF INCHARGE

Submitted for I Year BCA Practical Examination held on _______________


in Computer Application Department, Arcot Sri Mahaalakshmi Women’s College
Villapakkam, Arcot.

EXAMINER I EXAMINER II
INDEX

EX. DATE TITLE PAGE SIGN


NO NO
1 PROGRAM USING
VARIABLES,CONSTANT,I/O
STATEMENT
2 PROGRAM USING OPERATORS
IN PYTHON

3 PROGRAM USING
CONDITIONAL STATEMENT

4 PROGRAM USING LOOPING


STATEMENT

5 PROGRAM USING JUMP


STATEMENT
6 PROGRAM USING FUNCTIONS

7 PROGRAM USING RECURSION

8 PROGRAM USING ARRAY

9 PROGRAM USING STRING

10 PROGRAM USING MODULES

11 PROGRAM USING LIST

12 PROGRAM USING TUPLES

13 PROGRAM USING
DICTIONARIES

14 PROGRAM USING FILE


HANDLING
PROGRAM USING VARIABLES, CONSTANTS, I/O STATEMENTS IN
PYTHON

TAX_RATE = 0.15
def main():
name = input(“Enter your name:”)
salary = float(input(“Enter your salary:”))
tax_amount = salary * TAX_RATE
net_salary = salary – tax_amount
print(“\n====payslip====”)
print(f”Name:{name}”)
print(f”Salary:${salary:.2f}”)
print(f”Tax Amount:${tax_amount:.2f}”)
print(f”Net Salary:${net_salary:.2f}”)
if__name__==”__main__”:
main()
PROGRAM USING VARIABLES, CONSTANTS, I/O STATEMENTS IN
PYTHON

OUTPUT

Enter your name: Lavanya


Enter your salary: 20000
====payslip====
Name: Lavanya
Salary: $20000.00
Tax Amount: $3000.00
Net Salary: $17000.00
PROGRAM USING OPERATORS IN PYTHON

def main():
num1=10
num2=5

#Addition
result_add= num1 + num2
print(“Addition”)
print(f”{num1} + {num2}= {result_add}”)

#subtraction
result_sub= num1- num2
print(“Subtraction”)
print(f”{num1} – {num2}= {result_sub}”)

#multiplication
result_mul= num1 * num2
print(“Multiplication”)
print(f”{num1} * {num2}= {result_mul}”)

#division
result_div= num1 / num2
print(“Division”)
print(f”{num1} / {num2}= {result_div}”)

if___name__==”__main__”:
main()
PROGRAM USING OPERATORS IN PYTHON

OUTPUT

Addition
10 + 5 = 15

Subtraction
10 – 5 = 5

Multiplication
10 * 5 = 50

Division
10 / 5 = 2.0
PROGRAM USING CONDITIONAL STATEMENTS

def main():
age= int(input(“Enter your age:”))
if age<18:
print(“You are a minor.”)
elif age>=18 and age<65:
print(“You are an adult.”)
else:
print(“You are a senior citizen.”)

if__name__== “__main__”:
main()
PROGRAM USING CONDITIONAL STATEMENTS

OUTPUT

Enter your age: 16


You are a minor.
Enter your age: 24
You are an adult.
Enter your age: 69
You are a senior citizen.
PROGRAM USING LOOPING STATEMENT

def tables():
n= int(input(“Enter any number:”))
print(“Multiplication table of”,n)
print(“********************”)
for i in range(1,11):
print(n, “x”, i , “=” , n*i)

print(tables)
PROGRAM USING LOOPING STATEMENT

OUTPUT

Enter any number: 4


Multiplication table of 4
********************
4x1=4
4x2=8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
PYTHON PROGRAM OF SQUARE ROOT USING JUMP
STATEMENT

import math
total_prime = 0
total_composite = 0
while(1):
num = int(input(“Enter the number:”))
if(num == 999):
break
elif num<0:
print(“Square root of negative number cannot be calculated”)
continue
else:
print(“Square root of”, num , “=” , math.sqrt(num))
PYTHON PROGRAM OF SQUARE ROOT USING JUMP
STATEMENT

OUTPUT
Enter the number: 225
Square root of 225: 15
Enter the number: 36
Square root of 36: 6
Enter the number: -16
Square root of negative number cannot be calculated
Enter the number: 999
PROGRAM USING FUNCTION IN PYTHON

def swap(a,b):
a,b=b,a
print(“After swap”)
print(“First number =”,a)
print(“Second number =”,b)

a = input(“Enter the first number:”)


b = input(“Enter the second number:”)
print(“Before swap”)
print(“First number =”,a)
print(“Second number =”,b)
swap(a,b)
PROGRAM USING FUNCTION IN PYTHON

OUTPUT
Enter the first number: 7
Enter the second number: 10
Before swap
First number = 7
Second number = 10
After swap
First number = 10
Second number = 7
PYTHON PROGRAM TO SOLVE THE FIBONACCI SEQUENCE
USING RECURSION

def fibonacci(n):
if n == 1 or n == 2:
return 1
else:
return fibonacci(n-1) + (fibonacci(n-2))

print (fibnoacci(7))
PYTHON PROGRAM TO SOLVE THE FIBONACCI SEQUENCE
USING RECURSION

OUTPUT
13
PYTHON PROGRAM USING ARRAY

numbers = [ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
sum_of_numbers = 0
count = 0
for num in numbers:
sum_of_numbers += num
count += 1

average = sum_of_numbers / count


print(“Sum of numbers:”, sum_of_numbers)
print(“Average of numbers:”, average)
print(“Total number of numbers in array list:”, count)
PYTHON PROGRAM USING ARRAY
OUTPUT
Sum of numbers: 550
Average of numbers: 55
Total number of numbers in array list: 10
PYTHON PROGRAM USING STRING

my_string = “Hello, World!”


print(“Original String:”,my_string)
string_length = len(my_string)
print(“Length of the string:”, string_length)
uppercase_string = my_string.upper()
print(“Convert string into capital letter:”,uppercase_string)
contains_world = “World” in my_string
print(“Contains “World” in given string:”, contains_world)
modified_string = my_string.replace(“World”, “Python”)
print(“Modified string:”, modified_string)
words = my_string.split()
print(“Words in the string:”, words)
count_l = my_string.count(‘l’)
print(“Count of ‘l’ in the string:”, count_l)
starts_with_hello = my_string.startswith(“Hello”)
print(“Starts with ‘Hello’:”, starts_with_hello)
ends_with_exclamation = my_string.endswith(“!”)
print(“Ends with ‘!’:”, ends_with_exclamation)
PYTHON PROGRAM USING STRING
OUTPUT
Original string: Hello, World!
Length of the string: 13
Convert string into capital letter: HELLO, WORLD!
Contains ‘World’: True
Modified string: Hello, Python
Words in the string: [‘Hello,’ , ‘World’]
Count of ‘l’ in the string: 3
Starts with ‘Hello’: True
Ends with ‘!’: True
PYTHON PROGRAM OF ARITHMETIC OPERATION USING
MODULE
#math_operation.py
def add(a,b):
return a + b
def subtract(a,b):
return a – b
def multiply(a,b):
return a * b
def divide(a,b):
if b == 0:
return “Cannot divide by zero”
return a / b

#main_program.py
import math_operation
result_add = math_operation.add(5,3)
result_subtract = math_operation.subtract(10,4)
result_multiply = math_operation.multiply(6,7)
result_divide = math_operation.divide(8,2)
print(“Addition:”,result_add)
print(“Subtraction:”, result_subtract)
print(“Multiplication:”, result_multiply)
print(“Division:”, result_divide)
PYTHON PROGRAM OF ARITHMETIC OPERATION USING
MODULE

OUTPUT
Addition: 8
Subtraction: 6
Multiplication: 42
Division: 4
PYTHON PROGRAM OF VARIOUS OPERATIONS USING LIST

numbers = [10, 20, 30, 40, 50]


print(“Original list:”, numbers)
print(“Element at index 2:”, numbers[2])
numbers[3]= 45
print(“Added 45 in the list:”,numbers)
numbers.append(60)
print(“Modified list:”, numbers)
numbers.remove(20)
print(“List after removed 20 in the list:”, numbers)
numbers.insert(1,15)
print(“current list:”, numbers)
list_length = len(numbers)
print(“Number of elements in the list:”, list_length)
is_present = 30 in numbers
print(“Element 30 is present in the list:”, is_present)
PYTHON PROGRAM OF VARIOUS OPERATIONS USING LIST

OUTPUT

Original list: [10, 20, 30, 40, 50]


Element in the index 2: 30
Added 45 in the list: [10, 20, 30, 45, 50]
Modified list: [10, 20, 30, 45, 50, 60]
List after removed 20 in the list: [10, 30, 45, 50, 60]
Current list: [10, 15, 30, 45, 50, 60]
Number of elements in the list: 6
Element 30 is present in the list: True
PYTHON PROGRAM USING TUPLES

fruits = (“apple”, “banana”, “cherry”, “dragon_fruit”)


print(“First fruit =”, fruits[0])
print(“Last fruit =”, fruits[-1])
print(“All fruits”)
for fruit in fruits:
print(fruit)
is_present = “kiwi” in fruits
print(“kiwi is present in the tuple=”, is_present)
#concatenate tuple
more_fruits = (“grapes”, “pineapple”)
combined_fruits = fruits + more_fruits
print(“Combined tuple of fruits=”, combined_fruits)
count_cherry = fruits.count(“cherry”)
print(“Number of cherry in the tuple=”, count_cherry)
index_banana = fruits.index(“banana”)
print(“Index of the banana in the tuple=”, index_banana)
PYTHON PROGRAM USING TUPLES

OUTPUT
First fruit = apple
Last fruit = dragon_fruit
All fruits
Apple
Banana
Cherry
Dragon_fruit
Kiwi is present in the tuple = false
Combined tuple of fruits = (‘apple’, ‘banana’, ‘cherry’, ‘dragon_fruit’,
‘grapes’, ‘pineapple’)
Number of cherry in the tuple = 1
Index of the banana in the tuple = 1
PYTHON PROGRAM OF STUDENT DETAIL USING
DICTIONARIES
student = {“name”: “Abirami”, “age”: 20, “grade”: “A”,
“courses”: [“maths”, “history”, “science”]}
print(“Student name:”, student[“name”])
print(“Student age:”, student[“age”])
print(“Student grade:”, student[“grade”])
student[“age”] = 24
student[“city”] = “Chennai”
print(student)
has_courses = “courses” in student
print(“Student has courses:”, has_courses)
keys = student.keys()
values = student.values()
print(“Keys in the dictionaries”)
for key in keys:
print(key)
print(“values in the dictionaries”)
for value in values:
print(value)
del student[“grade”]
has_grade = “grade” in student
print(“Does ‘grade’ exists in a dictionaries after removal?:”, has_grade)
PYTHON PROGRAM OF STUDENT DETAILS USING
DICTIONARIES
OUTPUT
Student name: Abirami
Student age: 20
Student grade: A
{‘name’: ‘Abirami’, ‘age’: 21, ‘grade’: ‘A’, ‘courses’: [‘maths’,
‘history’, ‘science’], ‘city’: ‘chennai’ }
Student has courses: True
Keys in the dictionaries
Name
Age
Grade
Courses
City
Values in the dictionaries
Abirami
21
A
[‘maths’, ‘history’, ‘science’]
Chennai
Does ‘grade’ exists in a dictionaries after removal?: false
PYTHON PROGRAM USING FILE HANDLING

#write data to a file


with open(“example.txt”, “w”) as file:
file.write(“Hello, world!\n”)
file.write(“This is a sample text file.\n”)
file.write(“Python file handling is easy.”)
#read data from the file
with open(“example.txt”, “r”)as file:
contents = file.read()
#print the contents of the file
print(“contents of the file:”)
print(contents)
PYTHON PROGRAM USING FILE HANDLING

OUTPUT:

You might also like