CS Practical File
CS Practical File
Submitted By -:
Divyansh Rajput
11th A
Submitted To-:
Mrs. Pooja Ma’am
ii
PROGRAM – 1
1. Write a python program to input a welcome message and
display it.
OUTPUT
iii
PROGR AM – 2
2. Input two numbers and display the larger/smaller
number.
#Checking Larger
if n1>n2:
print (n1," is larger.")
elif n2>n1:
print (n2," is larger")
else:
print("You have entered equal number.")
#Checking Smaller
if n1<n2:
print(n1," is smaller.")
elif n2<n1:
print(n2," is smaller")
else:
print("You have entered equal number.")
iv
OUTPUT
v
PROGRAM – 3
3. Generate the following patterns using nested loop.
for i in range(1,6):
for j in range(1,i+1):
print("*",end=" ")
print()
for i in range(6,1,-1):
for j in range(1,i):
print(j,end=" ")
print()
for j in range(65,i+1):
print(chr(j),end="")
print()
vi
OUTPUT
Pattern 1-
Pattern 2-
Pattern 3-
vii
PROGRAM – 4
4. Write a program to Find the Area and Perimeter of The
Rectangle .
A=l*b
P=2*(l+b)
print("Area of Rectangle=",A)
print("Perimeter of Rectangle=",P)
OUTPUT
viii
PROGRAM – 5
5. Write a program to input a number and check if the number
is a prime or composite number.
if n>1:
for i in range(2,n):
if n%i==0:
f=1
break
else:
f=0
else:
if f==1:
else:
OUTPUT
x
PROGRAM – 6
6. Write a python program to compute the greatest common
divisor and least common multiple of two integers.
# Calculating LCM
lcm = fn * sn/ gcd
print('LCM of %d and %d is %d' %(fn, sn, lcm))
OUTPUT
xi
PROGRAM – 7
7. Write a program to Find the Factorial of a Number.
OUTPUT
xii
PROGRAM – 8
8. Program that reads two numbers and an arithmetic operator
and displays the computed result
OUTPUT
xiii
PROGRAM – 9
9. Write a program to find the largest number in a list.
#Variable declaration
n=int(input("Enter the number of elements:"))
l=[]
m=0
#Input from user
for i in range(n):
val=int(input("Enter element:"))
l.append(val)
print("The original list:",l)
#Finding maximum
for i in l:
if i>m:
m=i
print("The maximum number is:",m)
OUTPUT
xiv
PROGRAM – 10
10. Write a program to create a dictionary with the roll
number, name and marks of n students in a class and
display the names of students who have marks above 75.
OUTPUT