Python Record Merged
Python Record Merged
Practical Record
2023 – 2026
LAB
Name :
Register No :
Subject :
Department Of Computer Application
PROGRAMMING IN PYTHON LAB
EXAMINER I EXAMINER II
INDEX
3 PROGRAM USING
CONDITIONAL STATEMENT
13 PROGRAM USING
DICTIONARIES
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
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
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
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)
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
#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
OUTPUT
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
OUTPUT: