You are on page 1of 33

Computer Science (083)

Practical File

Submitted To: Submitted By:


Mr. Abhishek Bhardwaj RAMPRATAP
TGT- Computer Science Sch No. : 5977
Class/Sec : XI-A
INDEX

Page
Ser Objective Signature
No
Write a Program in Python to check whether a given
(i) 1
number is Armstrong Number?
Write a Program in Python to find MAX number among
(ii) 2
three numbers.
Write a Program in Python to print Fibonacci Series for a
(iii) 3
number.
Write a Program in Python to print table for a given number
(iv) 4
by using for loop.
Write a Program in Python to Input a number and check if
(v) 5
the number is a prime or composite number.
Write a Program in Python to print following pattern.
12345
1234
(vi) 6
123
12
1
Write a Program in Python to print following * pattern.
Enter the Number of Rows : 04
*******
(vii) 7
*****
***
*
Write a Program in Python to find out middle number among
(viii) 8
three numbers.
Write a Program in Python to print following * pattern.
*
**
(ix) 9
***
****
*****
Write a Program in Python to Input a string and determine
(x) 10
whether it is a palindrome or not?
Write a Program in Python to find sum of list elements.
(xi) 11
Write a Program in Python to find Min or Max number in the
(xii) 12
List.
(xiii) Write a Program in Python to Reverse the List itself. 13
Write a Program in Python to Shift all the elements of the
(xiv) 14
List one step Left.
Write a Program in Python to count the number of times a
(xv) 15
character appears in a given string using a dictionary.
Write a Program in Python to Delete a given number from
(xvi) the List. 17
Page
Ser Objective Signature
No
Write a Program in Python to accept a List & a value ‘n’ 18
(xvii)
from user & Left shift all elements of List ‘n’ times.
Write a Program in Python to accept a List & a value ‘n’ 19
(xviii)
from user & Right shift all elements of List ‘n’ times.
Write a Program in Python to Store Students’ detail in 21
(xix) Dictionary and Display Information on the basis of School
Number.
Write a Program in Python to Insert an element at a given 23
(xx) position in the List.
PROGRAM – 1

Objective:
Write a Program in Python to check whether a given number is
Armstrong Number?

Program Code:

i=int(input("Enter the Number to Check : "))


org=i
sum=0
while i>0:
sum=sum+(i%10)*(i%10)*(i%10)
i=i//10
if sum==org:
print("Given Number is Armstrong Number")
else:
print("Given Number is not Armstrong Number")

Output:

[5977] Page 1
PROGRAM – 2

Objective:
Write a Program in Python to find MAX number among three numbers.

Program Code:

num1= int(input("Enter the first number : "))


num2= int(input("Enter the second number : "))
num3= int(input("Enter the third number : "))
if (num1>=num2) and (num1>=num3):
largest=num1
elif (num2>=num1) and (num2>=num3):
largest=num2
else:
largest=num3
print("The largest number is :",largest)

Output:

[5977] Page 2
PROGRAM – 3

Objective:
Write a Program in Python to print Fibonacci Series for a number.

Program Code:
i=int(input("Enter how many numbers of Fibonacci
series to be printed : "))
a=0
b=1
c=0
for z in range(i):
print(c)
a=b
b=c
c=a+b
Output:

[5977] Page 3
PROGRAM – 4

Objective:
Write a Program in Python to print table for a given number by using for
loop.

Program Code:
num=int(input("Enter the number to print table of :
"))
for i in range (1,11):
print(num,'x',i,'=',num*i)
Output:

[5977] Page 4
PROGRAM – 5

Objective:
Write a Program in Python to Input a number and check if the number is
a prime or composite number.
Program Code:
n=int(input("enter any number : "))

if (n==0 or n==1):

print(n,"number is neither prime nor composite:")

elif n>1:

for i in range (2,n):

if(n%i==0):

print(n,"is a composite number")

break

else:

print(n,"number is prime number ")

else:

print(n,"enter positive number only")

Output:

[5977] Page 5
PROGRAM – 6

Objective:

Write a Program in Python to print following pattern.

12345

1234

123

12

1
Program Code:

rows=int(input("enter the rows"))


for i in range (rows,0,-1):
for i in range (1,i+1):
print(i,end='')
print("\r")

Output:

[5977] Page 6
PROGRAM – 7

Objective:
Write a Program in Python to print following * pattern.

Enter the Number of Rows : 04

*******

*****

***

Program Code:

a=7
for i in range(4):
print("*"*a)
print(" "*i,end=" ")
a=a-2

Output:

[5977] Page 7
PROGRAM – 8

Objective:
Write a Program in Python to find out middle number among three
numbers.

Program Code:

num1=int(input("Input first number: "))


num2=int(input("Input second number: "))
num3=int(input("Input tird number: "))
if num1>num2:
if num1<num3:
mid= num1
elif num2>num3:
mid= num2
else:
mid= num3
else:
if num1>num3:
mid= num1
elif num2<num3:
mid= num2
else:
mid= num3
print("The middle number is",mid)

Output:

[5977] Page 8
PROGRAM – 9

Objective:
Write a Program in Python to print following * pattern.

**

***

****

*****
Program Code:
n=int(input("Enter the number of lines : "))
for i in range(1,n+1):
print("*"*i)
Output:

[5977] Page 9
PROGRAM – 10

Objective:
Write a Program in Python to Input a string and determine whether it is a
palindrome or not?

Program Code:
string=input("Enter the string to check : ")
if string==string[::
string==string[::-1]:
print("The string is Palindrome.......")
else:
print("The string is not Palindrome......")

Output:

[5977] Page 10
PROGRAM – 11

Objective:
Write a Program in Python to find sum of list elements.

Program Code:
L=[]
size=int(input("Enter the size of list : "))
for i in range(size):
x=int(input("Enter the elements of the list : "))
L.append(x)
print("The original list is : ",L)
sum=0
for i in range(size):
sum=sum+L[i]
print("The sum of all numbers is : ",sum)
Output:

[5977] Page 11
PROGRAM – 12

Objective:
Write a Program in Python to find Min or Max number in the List.

Program Code:
L=[]
size=int(input("Enter the size of list : "))
for i in range(size):
x=int(input("Enter the elements of the list : "))
L.append(x)
print("The original list is : ",L)
max=L[0]
for i in range(size):
if(max<L[i]):
max=L[i]
print("The max number among the list is : ",max)
min=L[0]
for i in range(size):
if(min>L[i]):
min=L[i]
print("The min number among the list is : ",min)
Output:

[5977] Page 12
PROGRAM – 13

Objective:
Write a Program in Python to Reverse the List itself.

Program Code:
L=[]

size=int(input("Enter the size of list : "))

for i in range(size):

x=int(input("Enter the elements of the list : "))

L.append(x)

print("The original list is : ",L)

a=0

b=size-1

while(a<b):

temp=L[a]

L[a]=L[b]

L[b]=temp

a=a+1

b=b-1

print("Reverse list is : ",L)

Output:

[5977] Page 13
PROGRAM – 14

Objective:
Write a Program in Python to Shift all the elements of the List one step
Left.

Program Code:
L=[]

size=int(input("Enter the size of list : "))

for i in range(size):

x=int(input("Enter the elements of the list : "))

L.append(x)

print("The original list is : ",L)

key=L[0]

for i in range(1,size):

L[i-1]=L[i]

L[size-1]=key

print("The list after one shit left : ",L)

Output:

[5977] Page 14
PROGRAM – 15

Objective:
Write a Program in Python to count the number of times a character
appears in a given string using a dictionary.

Program Code:
string=input("Enter the string to check : ")

dict={}

for i in string:

if i in dict:

dict[i]+=1

else:

dict[i]=1

print("The count of all characters is : ",dict)

Output:

[5977] Page 15
PROGRAM – 16

Objective:

Write a Program in Python to Delete a given number from the List.

Program Code:
L=[]
size=int(input("Enter the size of list : "))
for i in range(size):
x=int(input("Enter the elements of the list : "))
L.append(x)
print("The original list is : ",L)
key=int(input("Enter the value to delete : "))
flag=0
for i in range(size):
if L[i]==key:
flag=1
pos=i
break
if flag==0:
print("Element not found in list.")
else:
for i in range(pos,size-1):
L[i]=L[i+1]
L.pop()
print("The list after deletation is : ",L)

[5977] Page 16
Output:

[5977] Page 17
PROGRAM – 17

Objective:

Write a Program in Python to accept a List & a value ‘n’ from user & Left
shift all elements of List ‘n’ times.

Program Code:
L=[]

size=int(input("Enter the size of list : "))

for i in range(size):

x=int(input("Enter the elements of the list : "))

L.append(x)

print("The original list is : ",L)

n=int(input("Enter iteration for right shift : "))

for x in range(n):

temp=L[0]

for i in range(1,size):

L[i-1]=L[i]

L[size-1]=temp

print("List after",n,"times left shift : ",L)

[5977] Page 18
Output:

[5977] Page 19
PROGRAM – 18

Objective:

Write a Program in Python to accept a List & a value ‘n’ from user &
Right shift all elements of List ‘n’ times.

Program Code:
L=[]

size=int(input("Enter the size of list : "))

for i in range(size):

x=int(input("Enter the elements of the list : "))

L.append(x)

print("The original list is : ",L)

n=int(input("Enter iteration for right shift : "))

for x in range(n):

temp=L[size-1]

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

L[i]=L[i-1]

L[0]=temp

print("List after",n,"times right shift : ",L)

Output:

[5977] Page 20
PROGRAM – 19

Objective:

Write a Program in Python to Store Students’ detail in Dictionary and


Display Information on the basis of School Number.

Program Code:
stud_DB={}

#Ask Input from User or 'Q' to Exit

while True:

data=input("Enter ID and name separated by comma


or type 'Q' to exit :")

if data=="Q":

break

ID,Name=data.split(',')

stud_DB.update({ID:Name})

#Show Dictionary

for x,y in stud_DB.items():

print(x,y)

#Searching Key and Value

key=input("Enter the ID to search :")

if key in stud_DB:

print("Key=",key,"Value=",stud_DB[key])

else:

print("key not found....")

[5977] Page 21
Output:

[5977] Page 22
PROGRAM – 20

Objective:

Write a Program in Python to Insert an element at a given position in the


List.

Program Code:
L=[]

size=int(input("Enter the size of list : "))

for i in range(size):

x=int(input("Enter the elements of the list : "))

L.append(x)

print("The original list is : ",L)

key=int(input("Enter the value to insert : "))

pos=int(input("Enter the position to insert value :


"))

L.append(None)

for i in range(size-1,pos-2,-1):

L[i+1]=L[i]

L[pos-1]=key

print("List after insertation is : ",L)

[5977] Page 23
Output:

[5977] Page 24
PROJECT

PROGRAM CODE:

def rowprint(x):

y=1

print("Sr.\t Items \t\tPrice")

for i,j in x.items():

print(y,"\t",i ," ", "\t\t₹",j[0])

y+=1

print()

def rowprint1(x):

y=1

print("Sr.\tItems \t\tQuantity \tPrice


\t\t\tTotal")

for i,j in x.items():

print(y,"\t",i[0:5] ,"\t\t",j[0],
"\t\t₹",j[1]/1000,"k","\t\t₹",(j[1]*j[0])/1000,"k")

y+=1

print()

def change(x):

(item,cost)=x.split(',')

store.update({item:[int(cost)]})

store={"CPU":[50000],"Mouse":[1800],"Keyboard":[1000]
,"Moniter":[20000],"Tablet":[15000],"Pendrive":[1850]
,"Router":[11500],\

[5977] Page 25
"Webcam":[1200],"Mic":[1800],"Headphone":[2300],"Spea
ker":[1300]}

while True:

a=input("Basic Instructions : \nPress 'O' If


Owner \nPress 'C' For Costumer \npress 'E' to exit :
")

cart={}

print()

if a=="O":

rowprint(store)

while True:

x=input('Basic Instructions : \nEnter To


Change Items \nIts Cost Seprated By Comma ","\n"D" to
Done: ')

print()

if x=="D":

break

change(x)

rowprint(store)

elif a=="C":

rowprint(store)

while True:

x=input('Basic Instructions : \nSelect


The Item Name To Buy\n"D" to Done: ')

if x=="D":

[5977] Page 26
break

elif x in store:

q=int(input('Enter Quantity of Item :


'))

print()

cart.update({x:[q,store[x][0]]})

for j,i in cart.items():

if i[0]==0:

cart.pop(j)

break

print("Your Cart \/")

rowprint1(cart)

else:

print("We Deeply Apologize For Our


Inconvienence as The Item Is Not Available")

print()

print()

sum=0

print("Your Bill \/")

rowprint1(cart)

for i in cart.values():

sum+=i[1]*i[0]

print("Total Amount :
\t\t\t\t\t\t\t₹",sum/1000,'k')

elif a=="E":

break

[5977] Page 27
else:

print("You enter Wrong Input")

[5977] Page 28
Output:

[5977] Page 29
[5977] Page 30

You might also like