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

Practical Programs to be print

The document is a record for Computer Science work at Sri Bala Vidyalaya for the academic years 2022-2023 and 2024-2025. It includes various Python programming exercises aimed at teaching students fundamental programming concepts such as loops, conditionals, and data structures. Each exercise consists of an aim, source code, output, and result, demonstrating successful execution of the programs.
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)
6 views

Practical Programs to be print

The document is a record for Computer Science work at Sri Bala Vidyalaya for the academic years 2022-2023 and 2024-2025. It includes various Python programming exercises aimed at teaching students fundamental programming concepts such as loops, conditionals, and data structures. Each exercise consists of an aim, source code, output, and result, demonstrating successful execution of the programs.
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
You are on page 1/ 43

SRI BALA VIDYALAYA

(Affiliated to CBSE, New Delhi)

Shanthi Nagar, Perambur,

Chennai – 600011

COMPUTER SCIENCE RECORD


2024 - 2025
2022 – 2023

NAME:

STD: SEC:

REGISTER NO:
SRI BALA VIDYALAYA
(Affiliated to CBSE, New Delhi)

…………………………… RECORD

Certified that this is the bonafide record of work done


by…………………………………………. of Std ………. in
the……………………. Laboratory

During the year ……………………

Dated ……………………

Teacher-in-charge

Principal External Internal


CONTENTS
EX PAGE TEACHER’S
DATE TITLE
NO. NO. INTIAL
1. CREATE A PYTHON PROGRAM THAT ACCEPTS
RADIUS OF A CIRCLE AND PRINT ITS AREA.
2. CREATE A PYTHON PROGRAM TO ACCEPT TWO
NUMBERS AND CHECK FIRST NUMBER IS
DIVISIBLE BY SECOND NUMBER.
3. CREATE A PYTHON PROGRAM TO ACCEPT AGE
AND CHECK ELIGIBLE TO VOTE OR NOT.
4. CREATE A PYTHON PROGRAM TO FIND LEAP
YEAR.
5. CREATE A PYTHON PROGRAM TO INPUT A
NUMBER AND PRINT ITS SQURARE IF IT IS ODD,
OTHERWISE PRINT ITS SQUAREROOT.
6. CREATE A PYTHON PROGRAM TO ENTER A
NUMBER AND CHECK IF IT IS A PRIME NUMBER
OR NOT.
7. CREATE A PYTHON PROGRAM TO PRINT
WHETHER A GIVEN CHARACTER IS AN
UPPPERCASE OR A LOWERCASE OR A DIGIT OR
ANY SPECIAL CHARACTER.
8. CREATE A PYTHON PROGRAM TO CALCULATE
THE FACTORIAL OF A NUMBER.
9. CREATE A PYTHON PROGRAM TO SHOW THE
DIFFERENCE BETWEEN BREAK AND CONTINUE
STATEMENT.
10. CREATE A PYTHON PROGRAM FOR NESTED
LOOP.
11. CREATE A PYTHON PROGRAM TO PRINT
FIBONACCI SERIES.
12. CREATE A PYTHON PROGRAM TO INPUT A
STRING AND CHECK IF IT IS A PALINDROME
STRING USING A STRING SLICE.
13. CREATE A PYTHON PROGRAM TO INPUT TWO
STRINGS AND CHECK STRING1 CONTAINED IN
STRING2 IF IT IS CONCATENATION IS DONE
WITH WORD 'RESTORE'.
14. CREATE A PYTHON PROGRAM TO SEARCH FOR
AN ELEMENT IN A GIVEN LIST OF NUMBER.
15. CREATE A PYTHON PROGRAM TO COUNT THE
FREQUENCY OF A GIVEN ELEMENT IN A LIST OF
NUMBERS.
16. CREATE A PYTHON PROGRAM TO COUNT THE
FREQUENCY OF A LIST OF ELEMENTS USING A
DICTIONARY.
17. CREATE A PYTHON PROGRAM TO SHOW
IDENTICAL ELEMENTS IN REVERSE ORDER.
18. CREATE A PYTHON PROGRAM TO DELETE THE
KEYS OF A DICTIONARY, ONE BY ONE IN LIFO
ORDER.
19. CREATE A PYTHON PROGRAM TO CREATE A
DICTIONARY WITH 10 KEYS FROM 0 TO 9.
20. CREATE A PYTHON PROGRAM TO INPUT A
TUPLE AND CREATE TWO NEW TUPLES FROM
IT.
EX:01 CREATE A PYTHON PROGRAM THAT ACCEPTS RADIUS OF A CIRCLE AND PRINT ITS ARE
A.

AIM: To write a python program that accepts radius of a circle and print ots area

SOURCECODE:

r = int(input("enter the radius of circle"))


area = 3.14*r*2
print("the area of the circle is",area)
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
= RESTART: C:/Users/Administrator/AppData/Local/Programs/Python/Python38/fex1.py
enter the radius of circle8
the area of the circle is 50.24
>>>

RESULT: Thus the python program is executed successfully.


EX:02 CREATE A PYTHON PROGRAM TO ACCEPT TWO NUMBERS AND CHECK FIRST NUMBER I
S DIVISIBLE BY SECOND NUMBER.

AIM: To write a python program to accept two numbers and check first number is divisible by second nu
mber.

SOURCECODE:

a = float(input("enter the first number"))


b = float(input("enter the second number"))
if a%b ==0:
print("the first number is fully divisible by second")
else:
print("the first number is not fully divisible by second")
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex2.py ========
enter the first number40
enter the second number20
the first number is fully divisible by second
>>>
enter the first number90
enter the second number20
the first number is not fully divisible by second
>>>

RESULT: Thus the python program is executed successfully.


EX:03 CREATE A PYTHON PROGRAM TO ACCEPT AGE AND CHECK ELIGIBLE TO VOTE OR NOT.

AIM: To write a python program to accept age and check eligible to vote or not.

SOURCECODE:

a = int(input ("enter your age"))


if a>=18:
print("you are eligible to vote")
else:
print("you are not eligible to vote")
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex3.py ========
enter your age25
you are eligible to vote
>>>
enter your age 16
you are not eligible to vote
>>>

RESULT: Thus the python program is executed successfully.


EX:04 CREATE A PYTHON PROGRAM TO FIND LEAP YEAR.

AIM: To write a python program to find leap year.

SOURCECODE:

a=int(input(’enter the year:’))


if a%4==0:
print(’this year is a leap year’)
else:
print(’this year is not a leap year’)
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex4.py ========
enter the year:2004
this year is a leap year
>>>
enter the year:2003
this year is not a leap year
>>>

RESULT: Thus the python program is executed successfully.


EX:05 CREATE A PYTHON PROGRAM TO INPUT A NUMBER AND PRINT ITS SQURARE IF IT IS OD
D,OTHERWISE PRINT ITS SQUAREROOT.

AIM: To write a python program to input a number and print its Square of it is odd, otherwise print its Squ
areroot.

SOURCECODE:

x = float(input("enter the number"))


import math
a = math.pow(x,2)
b = math.sqrt(x)
if x%2!=0:
print("the value of square is",a)
else:
print("the value of square is",b)
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex5.py ========
enter the number45
the value of square is 2025.0
>>>

RESULT: Thus the python program is executed successfully.


EX:06 CREATE A PYTHON PROGRAM TO ENTER A NUMBER AND CHECK IF IT IS A PRIME NUMB
ER OR NOT.

AIM: To write a python program to enter a number and check if it is a prime number or not.

SOURCECODE:

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


for i in range(2,num//2+1):
if num%i ==0:
print("it is not a prime number:")
break
else:
print("it is a prime number:")
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex6.py ========
enter the number 4
it is not a prime number:
>>>
enter the number19
it is a prime number:

RESULT: Thus the python program is executed successfully.


EX:07 CREATE A PYTHON PROGRAM TO PRINT WHETHER A GIVEN CHARACTER IS AN UPPPER
CASE OR A LOWERCASE OR A DIGIT OR ANY SPECIAL
CHARACTER.

AIM: To write a python program to print whether a given character is an uppercase or a lowercase or a d
igit or any special
character.

SOURCECODE:

ch = input("enter a single character")


if ch>=’A’ and ch<=’Z’:
print("you have entered an upper character")
elif ch>=’a’ and ch<=’z’:
print("you have entered a lower character")
elif ch>=’0’ and ch<=’9’:
print("you have entered a digit")
else:
print("you have entered a special character")
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex7.py ========
enter a single characterE
you have entered an upper character
>>>
enter a single character5
you have entered a digit
>>>
enter a single character *
you have entered a special character
>>>
enter a single characterz
you have entered a lower character

RESULT: Thus the python program is executed successfully.


EX:08 CREATE A PYTHON PROGRAM TO CALCULATE THE FACTORIAL OF A NUMBER.

AIM: To write a python program to calculate the factorial of a number.

SOURCECODE:

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


fact=1
a=1
while a<=num:
fact*=a
a+=1
print("the factorial of ",num,"is",fact)
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex8.py ========
enter the number5
the factorial of 5 is 1
the factorial of 5 is 2
the factorial of 5 is 6
the factorial of 5 is 24
the factorial of 5 is 120
>>>

RESULT: Thus the python program is executed successfully.


EX:09 CREATE A PYTHON PROGRAM TO SHOW THE DIFFERENCE BETWEEN BREAK AND CONT
INUE STATEMENT.

AIM: To write a python program to show the difference between break and continue statement.

SOURCECODE:

print("the loop with break")


for i in range(1,11):
if i%3 ==0:
break
else:
print(i)
print("the loop with continue")
for i in range(1,11):
if i%3 ==0:
continue
else:
print(i)
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/fex9.py ========
the loop with break
1
the loop with continue
10
2
the loop with continue
10
>>>

RESULT: Thus the python program is executed successfully.


EX:10 CREATE A PYTHON PROGRAM FOR NESTED LOOP.

AIM: To write a python program for nested loop.

SOURCECODE:

for i in range(1,6):
print( )
for j in range(1,i):
print("*",end=’ ’)
OUTPUT:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
======== RESTART: C:/Users/Administrator/Desktop/fex10.py ========

*
**
***
****
>>>

RESULT: Thus the python program is executed successfully.


EX:01 CREATE A PYTHON PROGRAM TO PRINT FIBONACCI SERIES.

AIM: To write a python program to print fibonacci series.

SOURCECODE:

t = int(input("Enter the value?"))


first = 0
second = 1
print("Fibonacci series is:")
print(first, ",", second, end=", ")

for i in range(2, t):


next = first + second
print(next, end=", ")
first = second
second = next
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========== RESTART: C:\Users\Administrator\Desktop\fi.py =========
Enter the value?8
Fibonacci series is:
0 , 1, 1, 2, 3, 5, 8, 13,
>>>
EX:02 CREATE A PYTHON PROGRAM TO INPUT A STRING AND CHECK IF IT IS A PALINDROME
STRING USING A STRING SLICE.

AIM: To write a python program to input a string and check if it is a palindrome string using a string slice.

SOURCECODE:

s = input("enter a string:")
if (s ==s[ : : -1]):
print(s,"is a palindrome")
else:
print(s,"is not a palindrome")
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/ex2a.py ========
enter a string:mirarim
mirarim is a palindrome
>>>
enter a string:mira
mira is not a palindrome
>>>
EX:03 CREATE A PYTHON PROGRAM TO INPUT TWO STRINGS AND CHECK STRING1 CONTAINE
D IN STRING2 IF IT IS CONCATENATION IS DONE WITH
WORD ’RESTORE’.
AIM: To write a python program to input two strings and check string1 contained in string2 if it is concate
nation is done
with word ’restore’

SOURCECODE:

s1 = input("enter string1:")
s2 = input("enter string2:")
print("original strings:",s1,s2)
if s1 in s2:
s3 = s2[0:4]+"restore"
print("final strings:",s1,s3)
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:/Users/Administrator/Desktop/ex2b.py ========
enter string1:rin
enter string2:shagrin
original strings: rin shagrin
final strings: rin shagrestore
>>>
EX:04 CREATE A PYTHON PROGRAM TO SEARCH FOR AN ELEMENT IN A GIVEN LIST OF NUMB
ER.

AIM: To write a python program to search for an element in a given list of number.

SOURCECODE:

lst = eval(input("enter list:"))


length = len(lst)
element = int(input("enter element to be searched for:"))
for i in range(0,length):
if element == lst[i]:
print(element,"found at index",i)
break
else:
print(element,"not found in given list")
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
==== RESTART: C:\Users\Administrator\Desktop\searchelement.py ====
enter list:[12,13,14,15,-12,-13,-14,-15]
enter element to be searched for:-15
-15 not found in given list
-15 not found in given list
-15 not found in given list
-15 not found in given list
-15 not found in given list
-15 not found in given list
-15 not found in given list
-15 found at index 7
>>>
EX:05 CREATE A PYTHON PROGRAM TO COUNT THE FREQUENCY OF A GIVEN ELEMENT IN A L
IST OF NUMBERS.

AIM: To write a python program to count the frequency of a given element in a list of numbers.

SOURCECODE:

lst = eval(input("enter list:"))


length = len(lst)
element = int(input("enter element:"))
count = 0
for i in range(0,length):
if element == lst[i]:
count+=1
if count ==0:
print(element,"not found in given list")
else:
print(element,"has frequency as",count,"in given list")
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
======= RESTART: C:\Users\Administrator\Desktop\countfrq.py ======
enter list:[12,13,14,15,16,16,16]
enter element:16
16 has frequency as 1 in given list
16 has frequency as 2 in given list
16 has frequency as 3 in given list
>>>
EX:06 CREATE A PYTHON PROGRAM TO COUNT THE FREQUENCY OF A LIST OF ELEMENTS US
ING A DICTIONARY.

AIM: To write a python program to count the frequency of a list of elements using a dictionary.

SOURCECODE:

import json
sentence = "this is a super idea this \ idea will change the idea of learning"
words = sentence.split()
d = {}
for one in words:
key = one
if key not in d:
count = words.count(key)
d[key] = count
print("counting frequencies in list\n",words)
print(json.dumps(d,indent = 1))
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
== RESTART: C:\Users\Administrator\Desktop\elementsusing dict.py =
counting frequencies in list
[’this’, ’is’, ’a’, ’super’, ’idea’, ’this’, ’\\’, ’idea’, ’will’, ’change’, ’the’, ’idea’, ’of’, ’learning’]
{
"this": 2,
"is": 1,
"a": 1,
"super": 1,
"idea": 3,
"\\": 1,
"will": 1,
"change": 1,
"the": 1,
"of": 1,
"learning": 1
}
>>>
EX:07 CREATE A PYTHON PROGRAM TO SHOW IDENTICAL ELEMENTS IN REVERSE ORDER.

AIM: To write a python program to show identical elements in reverse order.

SOURCECODE:

tup = eval(input("enter input for tuple:"))


t1 = tup[2:8:2]
t2 = tup[-3:-9:-2]
t3 = t2[ : : -1]
if t3 == t1:
print("the two tuples contain the same elements in reversed order")
else:
print("the two tuples contain different elements")
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
====== RESTART: C:\Users\Administrator\Desktop\twotuples.py ======
enter input for tuple:1,2,3,4,5,6,7,8,9,10,11
the two tuples contain different elements
>>>
EX:08 CREATE A PYTHON PROGRAM TO DELETE THE KEYS OF A DICTIONARY,ONE BY ONE IN
LIFO ORDER.

AIM: To write a python program to delete the keys of a dictionary, one by one inn LIFO order.

SOURCECODE:

stu = {1:’neha’,2:’saima’,3:’aaa’,4:’anu’,5:’sha’}
while len(stu)>=1:
print("element deleted:",stu.popitem())
print("All elements of the dictioary got deleted in LIFO order")
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: C:\Users\Administrator\Desktop\lifo.py ========
element deleted: (5, ’sha’)
element deleted: (4, ’anu’)
element deleted: (3, ’aaa’)
element deleted: (2, ’saima’)
element deleted: (1, ’neha’)
All elements of the dictioary got deleted in LIFO order
>>>
EX:09 CREATE A PYTHON PROGRAM TO CREATE A DICTIONARY WITH 10 KEYS FROM 0 TO 9.

AIM: To write a python program to create a dictionary with 10 keys frome 0 to 9.

SOURCECODE:

new_dict = {}
for i in range(10):
new_dict.setdefault(i)
print("dictionary is")
print(new_dict)
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
======= RESTART: C:\Users\Administrator\Desktop\default.py =======
dictionary is
{0: None, 1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, 8: None, 9: None}
>>>
EX:10 CREATE A PYTHON PROGRAM TO INPUT A TUPLE AND CREATE TWO NEW TUPLES FRO
M IT.

AIM: To write a python program to input a tuple and create two new tuples from it.

SOURCECODE:

tup = eval(input("enter input for tuple:"))


t1 = tup[ : : -3]
t2 = tup[2:8:2]
print("two created tuples are:")
print("tuple1:",t1)
print("tuple 2:",t2)
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
====== RESTART: C:\Users\Administrator\Desktop\reversetup.py =====
enter input for tuple:1,2,3,4,5,6,7,8,9,10,11
two created tuples are:
tuple1: (11, 8, 5, 2)
tuple 2: (3, 5, 7)
>>>

You might also like