Python Program File
Python Program File
PRACTICAL FILE
ON
PYTHON PROGRAMS
Submitted by:
Prince Kumar
Roll No.- 34
COMPUTER SCIENCE
PYTHON PRACTICAL PROGRAMS
I. Program to obtain length and breadth of a rectangle and calculate its area.
Solution.
#to input length and breadth of a rectangle and calculate its area
length = float( input("Enter length of the rectangle : t'))
breadth= float( input Enter breadth of
the rectangle: area=length * breadth
print ("Rectangle specifications print
("Length = ", length) print ("breadth ",
breadth) print ("Area = area)
the number:"))
+ I):
# If num is divisible by any number
# between 2 and num, it is not prime
if num > 1:
for n in range(2, val): if (val % n) o:
break
else:
print(val)
135
File Edit Shell Debug Options Window Help 1357
3.8.0 01
Solution. tel) on win32
Type "help", "copyright","credits"
num=int(input("Enter the number:'
for a in range (2, num, 2): for b in
range (I, a, 2): print (b, end t)) print
()
372.24
9. Write a program to input a character and to print whether a given character is
an alphabet, digit or any other character.
SOURCE CODE:
a character: ") if
ch.isalpha():
print(ch, "is an alphabet") elif
ch.isdigit():
print(ch, "is a digit") elif
ch.isalnum():
print(ch, "is alphabet and
numeric")
SOURCE CODE:
Lst=eval(input ( " Enter list :"))
length=Ien(Lst) element=int(input( "
Enter element count=O for i in
range(O, length):
if element==Lst [i]:
count I if
count O:
print (element, "not found in given list") else:
print(element, "has frequency as", count, "in given list")
4
Name ) the student : Ezajwai
factorial(n-l)
the
number: if num < O:
factorial does not exist for negative numbers")
0:
elif num print("The factorial of O is 1") else:
print("The factorial of ",num," is ", factorial(num))
120
2 3 5 8 13 21 34 55
for i in range(n):
the number"))
a.append(num) print (a)
max=a [O] for i in
range(n): if(max<a[i]):
print
RESTART: C: 'Program Files
loc=-l
for i in range(L):
num=int(input("Enter the number"))
a.append(num) print (a)
n=len(a) for p in for i
in range(O,n-I): if
Entez the
Enter the 40 [10, 401
50
[10, 40, 501
Enter the nurEe:20
[10, 40, 50, 201
Enter the number30
[10, 40, so, 20, 30)
The sorted Iidt is : [10, 40, 20, so, 301
The sorted liat is : [10, 40, 20, 30, 501
The sorted list is • [10, 20, 40, 30, 501
The sorted : 20, 30, 40,
17.Program to input two numbers and print their LCM and HCF.
SOURCE CODE:
X=int(input("Enter first number:"))
int (input("Enter second
number:")) if X smaller = Y
smaller = X
for i in range(l,
smaller + I):
% and (Y 0/0 i = O) ) •
hcf=i
Y) / hcf Ente: number:5RESTART: H.C.F. of", X, "and Y, "is",
hcf) Enter second number: 4
The a.C.F. S and 4 1
L.C.M. X, "and Y, "is", lcm) The L.c.Y. s and 4 13 20.0
the number of
elements; 0))
for I in range(n):
m=int(input("enter the number:"))
d.append(m)