You are on page 1of 15

SESSION-2022-23

Computer Science 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.

wl_msg = input(“Enter the welcome


message:”)
print(wl_msg)

OUTPUT
iii

PROGR AM – 2
2. Input two numbers and display the larger/smaller
number.

n1=input ("Enter the first number to check:")


n2=input ("Enter the second number to check:")

#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.

#Code For Pattern1

for i in range(1,6):

for j in range(1,i+1):

print("*",end=" ")

print()

#Code for Pattern2

for i in range(6,1,-1):

for j in range(1,i):

print(j,end=" ")

print()

#code for pattern 3

for i in range (65,70):

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 .

# To Find the Area and Perimeter of Rectangle

l=int(input('Enter the Length of Rectangle:'))


b=int(input('Enter the Breadth of 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.

n=int(input("Enter number to check:"))

if n>1:

for i in range(2,n):

if n%i==0:

f=1

break

else:

f=0

elif n==0 or n==1:

print(n, " is not a prime number nor composite


number")

else:

print(n," is a composite number")

if f==1:

print(n, " is not a prime number")

else:

print(n," is a prime number")


ix

OUTPUT
x

PROGRAM – 6
6. Write a python program to compute the greatest common
divisor and least common multiple of two integers.

# Reading two numbers from user


fn = int(input('Enter first number: '))
sn = int(input('Enter second number: '))
gcd = 1
for i in range(1,fn +1):
if fn%i==0 and sn%i==0:
gcd = i
# Displaying GCD
print('HCF or GCD of %d and %d is %d' %(fn, sn,gcd))

# 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.

num = int(input("Enter a number: "))


factorial = 1
if num < 0:
print(" Factorial does not exist for negative
numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

OUTPUT
xii

PROGRAM – 8
8. Program that reads two numbers and an arithmetic operator
and displays the computed result

num1=float(input("Enter first number:"))


num2=float(input("Enter second
number:"))
op=input("Enter operator[+-*/]:")
result=0
if op =='+':
result=num1+num2
elif op =='-':
result=num1-num2
elif op =='*':
result=num1*num2
elif op =='/':
result=num1/num2
else :
print("Invalid Operator!!")
print(num1,op,num2,'=',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.

#Input for Number of stude


n=int(input("How many students?:"))
#Empty Dictionary
stu={}
#Data Input
for i in range(n):
print("Enter details of student:")
rn=int(input("Enter roll number:"))
name=input("Enter Name:")
marks=float(input("Enter Marks:"))
stu[rn]=[name,marks]
#Logic to display detail of students more than 75
marks
for i in stu:
if stu[i][1]>75:
print("Name:",stu[i][0],"Marks:",stu[i][1])
xv

OUTPUT

You might also like