0% found this document useful (0 votes)
7 views26 pages

Python Programming Exercises Guide

The document contains a series of exercises aimed at teaching programming concepts using Python, including algorithms and code snippets for various tasks such as checking leap years, calculating factorials, generating Fibonacci series, and performing file operations. Each exercise outlines its aim, algorithm, and corresponding code to demonstrate the implementation of the concept. The exercises also cover topics like classes and objects, dictionary methods, and SQLite database operations.

Uploaded by

ponmaniasikha
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)
7 views26 pages

Python Programming Exercises Guide

The document contains a series of exercises aimed at teaching programming concepts using Python, including algorithms and code snippets for various tasks such as checking leap years, calculating factorials, generating Fibonacci series, and performing file operations. Each exercise outlines its aim, algorithm, and corresponding code to demonstrate the implementation of the concept. The exercises also cover topics like classes and objects, dictionary methods, and SQLite database operations.

Uploaded by

ponmaniasikha
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

EXERCISE NO : 1

DATE:3.7.2025
LEAP YEAR​
AIM:
PRINT THE GIVEN YEAR IS LEAP YEAR

ALGORITHM:
Step1:start

Step2:read the value of a

Step3:if(a%4==0):

Display leap year else display not a leap year

Step4:stop

CODE:
a=int(input(“enter the year”))

if((a%4)==0):

print(“leap year”)

else:

print (“not a leap year”)


EXERCISE NO-3
DATE:3.7.2025
SUM OF SERIES
AIM:
To with a program to print the sum of series of the given number.

ALGORITHM:
Step1:start

Step2:read the value of n

Step3:declare the variable total 0

Step4:repeat the steps unit I in range(1,n+1)

Step5: display the value of total

Step6: stop

CODE:
n=int(input(“enter the number”))

s=0
for I in range (1,n+1)

s=s+1

print(“the sum of series”,s)

EXERCISE-2
DATE: 3.7.2025
DAYS OF THE WEEK
AIM:
To write a program for find the days of the week

ALGORITH:
Step1: start

Step2: read the value of day

Step: if day is equal to 1

Display Sunday

Else if the day is equal to 2


Display Monday

Else if day is equal to 3

Display Tuesday

Else if day is equal to 4

Display Wednesday

Else if day is equal to 5

Display Thursday

Else if day is equal to 6

Display Friday

Else if day is equal to 7

Display Saturday

CODE:
Day=int(input(“enter the day”))

If(day==1):

Print (“Sunday”)

elif(day==2):

Print (“Monday”)

elif(day==3):

print (“Tuesday”)

elif(day==4):

print (“Wednesday”)

elif(day==5):

print (“Thursday”)

elif(day==6):

print (“Friday”)

elif(day==7):

print (”Saturday”)​
else:
print (“error”)

EXERCISE NO-4
DATE: 7.7.2025
Factorial
AIM:
To write a program to print the factorial value of a given number

ALGORTHM:
Step1: start

Step2: read the value of n

Step3: declare the variable total-n

Step4: repeat the steps until I in range (1,n+1)

Total-total*i

Step5: display the value of total

Step6: stop

CODE:
n=int(input(“enter a number”))
total=1

for I in range (1,n+1)

total=total*a

print(“factorial”,total)

EXERCISE NO: 5
DATE: 11.7.2025
MULTIPLICATION TABLE
AIM:
To write a program to print a multiplication table of the given number

ALGORITHM:
Step1: start

Step2: read the value of n

Step3: declare the variable=1

Step4: repeat steps until i<=10

Display the message (i, ”x” , n , ”=” , i*n)


Step5: increment i by 1

Step6: stop.

CODE:
n=int(input(“enter the number”))

i=1

while(i<=10):

print (I,”x”,n,”=”,i*n)

i=i+1

EXERCISE NO-6
DATE: 11.7.2025
GREATEST OF THREE NUMBERS
AIM:
To write a program to display the greatest of the given three numbers
ALGORITHM:
Step1: start

Step2: read the value of a, b, c.

Step3: if a is greater than b & a is greater than c

Display a is the greatest number

Else is greater than a & b is greater than c

Display b is the greatest number

Or else display c is the greatest number.

Step4: stop

CODE:
a=int(input(“enter the number”))

b=int(input(“enter the number”))​


c=int(input(“enter the number”))

if((a>b)&(a>c)):

print(a,”is the greatest number”)​


elif ((b>a)&(b>c)):​
print(b,”is the greatest number”)​
else:

print(c,”is the greatest number”)


EXERCISE NO: 7
DATE: 18.7.2025
FIBONACCI SERIES
AIM:
To write a program to print the fibonacci Series of a given number

ALGORITHM:
Step1: start

Step2: declare the variable first=0 and second=1

Step3: print the value of first

Step4: print the value of second

Step5: declare the variable i=1

Step6: repeat the steps until (i<=n)

Third=first + second

Display (third)

First = second

Second = third

Step7: stop

Code:
First=0

Second=1

Print (first)

Print (second)

n=int(input(“enter the number of times”))

i=1

while(i<=n):
third=first+second

print(third)

first=second

second=third

i=i+1

EXERCISE NO: 8
DATE: 18.7.2025
SEARCHING A CHARACTER IN A GIVEN
STRING
AIM:
To write a python program to print whether a given character is in a given string.

ALGORITHM:
Step1: start

Step2: read the value of a.

Step3: read the value of b.


Step4: if (b in a)

Display character found

Or else display character not found

Step5: stop

Code:
a=input (“enter the string”)

b=input (“enter the character”)

if (b in a):

print (“character found”)

else:

print(“character not found”)

EXERCISE NO: 9
DATE: 22.7.2025
ARRAY SEARCH
AIM:
To write a program that returns the largest element is an array

ALGORITHM:
Step1: start

Step2: declare the variable with some values

Step3: repeat the steps until I in range [len(my array)]

Display (my array[1])

Step4: assign m=0

Step5: repeat the steps until 1 in range [len(my array)]

If m <my array [1]

m= my array [1]

step6: display m as the largest element

step7: stop

CODE:
Myarray=[45,23,76,12,33]

Print(“the given elements are:”)

For I in range (len(myarray)):

Print(myarray[i])

M=0

For I in range (lwn(myarray)):

If m<myarray[i]

m=myarray[i]

print(“the largest is:”,m


EXERCISE NO: 10
DATE: 26.7.2025
ARRAY MULTIPLICATION
AIM:
To write a program to print multiplication in array

ALDORITHM:
Step1: start

Step2: import numpy as np

Step3: declare the value for a and b np array

Step4: print the array a and b

Step5: declare variable m

Step6: multiply array a and b, store the values in m and display

Step7: stop

CODE:
Import numpy as np

a=[Link]([2,8]),([7,4])

b=[Link]([1,5]),([3,6])
print(“first array”,a)

print(“second array”,b)

m=[Link](a,b)

print(m)

EXERCISE NO: 11
DATE: 29.7.2025
DICTIONARY METHODS
AIM:
To write a program to print the dictionary methods

ALGORITHM:
Step1: start

Step2: create a dictionary

Step3: display the dictionary


Step4: use the methods/ operations adding a items clear (), items (), key (), value (), get (key) on the
dictionary and display

Step4: stop

CODE:
Dict ={“name”=”sathiya”,

“age”=17,

“mark”=90}

Print (dict)

Dict [“department”]=”bca”

Print (dict)

Print ([Link]())

Print ([Link]())

Print ([Link](name))

Print ([Link](age))

[Link]()

Print (dict)
EXERCISE NO: 12
DATE: 4.8.2025
LIST OPERATION

AIM:
To write a program to print the list operations

ALGORITHM:
Step1: start

Step2: create a list

Step3: display the list

Step4: use the operations: append(), count(), index(), pop(), pop(index), insert(index, element),
sort(), remove(element), len(), reverse() on the list and display

Step5: stop

Code:
list=["tamilnadu","delhi","goa","punjab"]

print (list)

[Link]("bihar")

print (list)

print ([Link]("goa"))

print ([Link]("punjab"))

[Link]()

print (list)

[Link](2,"andhra pradesh")

print (list)

[Link]()

print (list)
[Link]("goa")

print (list)

[Link]()

print (list)

print (len(list))

EXERCISE NO: 13
DATE: 11.8.2025
FILE OPERATIONS
AIM:
To write a program to print the file operations

ALGORITHM:
Step1: start

Step2: open a file ex1. Txt in write mode


Step3: write content to the file with write() method

Step4: close the file

Step5: open the file in read mode

Step6: read the content of the file with read() method and use the attributes name, closed, mode
and display

Step7: close the file

Step8: open the file in append mode

Step9: write the additional content to the file and display

Step10: close the file

Step11: stop

CODE:
#writing a file

f=open("[Link]","w")

[Link]("welcome")

[Link]()

#file attributes

f=open("[Link]","r")

print ([Link]())

print ([Link])

prime ([Link])

print ([Link])

[Link]()

#reading a file

f=open("[Link]","r")

print ([Link]())

[Link]()
EXERCISE NO: 14
DATE: 11.8.2025
SWAPPING OF TWO NUMBERS
AIM:
To write a program to display the swapping of two numbers

ALGORITHM:
Step1: start

Step2: read the values of a and b

Step3: print the values of a

Step4: print the values of b

Step5: set (a,b)=(b,a)

Step6: print the values of “a” after swapping

Step7: print the value of “b” after swapping

Step8: stop
CODE:
a=int(input("enter the first number"))

b=int(input("enter the second number"))

print (a)

print (b)

(a,b)=(b,a)

Print ("after interchanging ,first number is",a)

print ("after interchanging, second number is",b)

EXERCISE NO: 15
DATE: 20.8.2025
PRIME NUMBERS
AIM:
To write a program to check whether the given number is prime number or not

ALGORITHM:
Step1: start

Step2: define a use-defined function prime (n)

Step3: declare variable s=0 and 1=2

Step4: repeat the steps until (i<n\2)

If(n%i==0)

S=1

I=i+1

Step5: if (s==0)

Display is a prime number

Or else display not a prime number

Step6: read the value of n

Step7: call the prime (n)

Step8: stop

CODE:
def prime(n):

s=0

i=2

while (i<=n/2):

if (n%i==0):

s=1

i=i+2

if (s==0):

print ("is a prime number")

else:

print ("not a prime number")


n=int(input("enter the number"))

prime (n)

EXERCISE NO: 16
DATE: 22.8.2025
CLASSES AND OBJECTS
AIM:
To write a program to create a class and to display details using classes in python.

ALGORITHM:
Step1: start

Step2: define a class with the name employee.

Step3: create user defined functions the details () to assign the value to data member such as
employee number, employee name, salary

Step4: display the details using display () user defined function.

Step5: create 3 objects to assign and display the details of 3 employees.

Step6: stop
CODE:
class employee:

def file_details(self,a,b,c):

[Link]=a

[Link]=b

[Link]=c

def display(self):

print([Link],[Link],[Link])

e1=employee()

e2=employee()

e3=employee()

e1.file_details(101,"AAA","rs.20000")

e2.file_details(102,"BBB","rs.30000")

e3.file_details(103,"CCC","rs.50000")

[Link]()

[Link]()

[Link]()
EXERCISE NO: 17
DATE: 28.8.2025
CONSTRUCTOR
AIM:
To write a to create a class and to display details using constructor

CODE:
Step1: start

Step2: define a class with name product

Step3: define the constructor which initializes the value for productname, quality, price

Step4; define the user defined function display() which is used to display the details

Step5: create 3 object to assign and display the details of 3 products

Step6: stop

CODE:
class product:

def __init__ (self,a,b,c):

[Link]=a

[Link]=b

[Link]=c

def display (self):

print([Link],[Link],[Link])

p1=product("biscuit",10,"rs.100")

p2=product("juice",15,"rs.200")

p3=product("cake",20,"rs.500")

[Link]()

[Link]()

[Link]()
EXERCISE NO: 18
DATE:
EMPLOYEE DETAILS
AIM:
To write a program to print employee details table using sqlite3

ALGORITHM:
Step1: start

Step2: import sqlite3 and connect to the database and cursor

Step3: create the table employee details with field of eno,name,deft,salary

Step4: insert 5 records o the table using insert commands

Step5: display the result using select command and fetchall()

Step6: delete the details of one employee using delete command

Step7: display the result using delete command fetchall()

Step8: update the salary of any one of employee using update command

Step9: display the result using select command and fetchall()


Step10: stop

CODE:
Import sqlite3

Conn=[Link] (“pyt,bd)

C=[Link]()

[Link](“create table pyt (eno number(4),ename char(15),dept char(6),salary number(8))”)

[Link](“insert into pyt values(101,’lubna’,’manager’,30000)”)

[Link](“insert into pyt values(103,’manisha’,’hr’,40000)”)

[Link](“insert into pyt values(104,’sanjana’,’sales manager’,50000)”)

[Link](“insert into pyt values(105,’priya’,’finance manager’,25000)”)

[Link](“select*from pyt”)

print([Link]())

[Link](“delete from pyt where eno=101”)

[Link](“update pyt set salary=20000 where eno=103”)

[Link](“select*form pyt”)

print([Link]())

You might also like