Practical Programs to be print
Practical Programs to be print
Chennai – 600011
NAME:
STD: SEC:
REGISTER NO:
SRI BALA VIDYALAYA
(Affiliated to CBSE, New Delhi)
…………………………… RECORD
Dated ……………………
Teacher-in-charge
AIM: To write a python program that accepts radius of a circle and print ots area
SOURCECODE:
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
>>>
AIM: To write a python program to accept two numbers and check first number is divisible by second nu
mber.
SOURCECODE:
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
>>>
AIM: To write a python program to accept age and check eligible to vote or not.
SOURCECODE:
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
>>>
SOURCECODE:
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
>>>
AIM: To write a python program to input a number and print its Square of it is odd, otherwise print its Squ
areroot.
SOURCECODE:
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
>>>
AIM: To write a python program to enter a number and check if it is a prime number or not.
SOURCECODE:
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:
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:
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
SOURCECODE:
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
>>>
AIM: To write a python program to show the difference between break and continue statement.
SOURCECODE:
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
>>>
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 ========
*
**
***
****
>>>
SOURCECODE:
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:
AIM: To write a python program to count the frequency of a given element in a list of numbers.
SOURCECODE:
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.
SOURCECODE:
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.
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: