0% found this document useful (0 votes)
26 views24 pages

Computer Science Lab Manual-1

The document is a Computer Science Lab Manual for Grade XI, detailing various Python programming exercises. Each exercise includes the aim, program code, output, and result verification for tasks such as displaying messages, comparing numbers, generating patterns, and manipulating lists and dictionaries. The manual serves as a practical guide for students to learn programming concepts through hands-on coding activities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views24 pages

Computer Science Lab Manual-1

The document is a Computer Science Lab Manual for Grade XI, detailing various Python programming exercises. Each exercise includes the aim, program code, output, and result verification for tasks such as displaying messages, comparing numbers, generating patterns, and manipulating lists and dictionaries. The manual serves as a practical guide for students to learn programming concepts through hands-on coding activities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

BISHOP DEVADASS

AMBROSE VIDYALAYA
(CBSE)

COMPUTER SCIENCE LAB MANUAL


GRADE XI

Prepared by,
M. George Fernandez,
PGT-CS,
BDAV.
1. Input a welcome message and display it.

Aim:

To write a python program to get input as a “Welcome Message” and display it.

Program:

welcome_message=input(“Enter welcome message:”)

print(“Hello,”, welcome_message)

Output:

Enter welcome message: GRADE XI


Hello, GRADE XI

Result:

Thus the above python program was executed and output verified.
2. Input two numbers and display the larger/smaller number.

Aim:

To write a python program to get two numbers as a input and display the larger/smaller
number.

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

num2 = input("Enter the second number: ")

if (num1 > num2):

print(num1," is greater than ",num2)

else:

print(num2," is greater than ",num1)

Output:

Enter the first number: 89

Enter the second number: 96

96 is greater than 89

Result:
Thus the above python program was executed and output verified.
3. Input three numbers and display the largest/smallest number.

Aim:

To write a python program to get three numbers as a input and display the largest/smallest
number.

Program:
number1 = int(input('Enter First number : '))

number2 = int(input('Enter Second number : '))

number3 = int(input('Enter Third number : '))

if (number1 > number2) and (number1 > number3):

largest_number = number1

elif (number2 > number1) and (number2 > number3):

largest_number = number2
else:

largest_number = number3

print("The largest of the 3 numbers is : ", largest_number)

Output:
Enter First number : 893562

Enter Second number : 32

Enter Third number : 45

The largest of the 3 numbers is : 893562

Result:
Thus the above python program was executed and output verified.
4. Generate the pyramid patterns using nested loop.

Aim:

To write a python program to generate the pyramid patterns using nested loop.

Program:

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

for i in range(size):

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

print(' ', end='')

for k in range(2 * i + 1):


print('*', end='')
print()

Output:

Enter the size: 5

***

*****

*******

*********

Result:
Thus the above python program was executed and output verified.
5. Determine whether a number is a perfect number, an armstrong number or a palindrome.

Aim:
To write a python program to determine whether a number is a perfect number, an
armstrong number or a palindrome.

Program:
#palindrome

number = int(input("Enter any Value: "))

reverse = 0

temp = number

while(temp > 0):

Reminder = temp % 10

reverse = (reverse * 10) + Reminder


temp = temp //10

print("Reverse of it is " ,reverse)

if(number == reverse):

print(number,"is a Palindrome" )

else:

print(number," is not a Palindrome")

#perfect number
sum1=0

for i in range(1,number):

if(number%i==0):

sum1=sum1+i

if (sum1==number):

print(number,"is a perfect number")

else:
print(number,"is not a perfect number")
#armstrong number

sum=0

temp=number

while temp>0:
digit=temp%10

sum+=digit**3

temp//=10

if number==sum:

print(number,"is an armstrong number")

else:

print(number,"is not a armstrong number")

Output:

Enter any Value: 153

Reverse of it is 351

153 is not a Palindrome

153 is not a perfect number

153 is an armstrong number

Result:

Thus the above python program was executed and output verified.
6. write a program to input two strings. If strings1 is contained in string2, then create a third
string with first four characters of strings2’ added with word ‘Restore’.

Aim:

to write a python program to input two strings. If strings1 is contained in string2,


then create a third string with first four characters of strings2’ added with word ‘Restore’.

Program:

S1=input (“Enter string 1:”)


S2=input (“Enter string 2:”)

print (“original string:”,s1,s2)

if s1 in s2:

s3=s2[0:4] +” Restore”

print (“final strings: “,s1,s3)

output :

enter string 1:rin

enter string 2: shagrin

original strings : rin shagrin

final strings: rin shagRestore

result:

Thus the above python program was executed and output verified.
7. program that reads a line and prints its statistics like.

Aim:
To write a python program that reads a line and prints its statistics like.

Program:

Line=input(“enter a line”)

Lowercount=upper count=0

Digitcount=alphacount=symcount=0

for a in line:
if a.is lower():
lowercount+=1

elif a.isupper():

uppercount+=1

elif a.isdigit():

digitcount+=1

elif a.isalpha():

alphacount+=1
elif aisalnum()!=true and a!=’ ‘ :

symcount+=1

print(“number od uppercase letters:” , uppercount)

print(“number of lowercase letters:” , lowercount)

print(“number of alphabets:”, alphacount)

print (“number of digits:”, digitcount)

print(“number of symbols:”,symcount)
Output:

Enter a line:hello 123,ZIPPY zippy zap

Number of uppercase letters :7

Number of lowercase letters :11


Number of alphabets:18

Number of digits:3

Number of symbols:1

Result:
Thus the above python program was executed and output verified.
8. write a program that inputs individual words of your school motto and joins them to make
a sting . it should also input day, month and year of your schools foundation date and print
the complete day

Aim:

To write a python program that inputs individual words of your school motto and joins
them to make a sting . it should also input day, month and year of your schools foundation
date and print the complete day.

Program :

print(“enter words of your school motto , one by one”)

w1=input(“enter word 1:”)


w2=input(“enter word 2:”)

w3=input("enter word 3:”)

w4=input("enter word 4:”)

motto =” ” .not join ([w1,w2,w3,w4])

print(“enter your schools foundation date.”)

dd=input(“enter dd:”)

mm=input(“enter mm:”)
yyyy=input("enter yyyy:”)

dt=”/”.join ([dd,mm,yyyy])

print(“school motto:”,motto)

print(“school foundation date:”,dt)

Output:

Enter words of your school motto,one by one


Enter word 1:words
Enter word 2: is

Enter word 3:a

Enter word 4:family

Enter your school’s foundation date.


Enter dd:01

Enter mm:10

Enter yyyy:1975

School motto :world is a family

School foundation date : 01/10/1975

Result:

Thus the above python program was executed and output verified.
9. write a program that inputs a list , replicates it twice and then prints the sorted list in
ascending and descending orders.

Aim:

To write a python a program that inputs a list , replicates it twice and then prints the
sorted list in ascending and descending orders.

Program:
val=eval(input(“enter a list:”))

print (“ original list :”, val)

val=val*2

print(“sorted in ascending order :”,val)

val.sort()

print(“sorted in ascending order :”, val)

val.sort(reverse =true)
print(“sorted in descending order:”, val)

Output :

Enter a list:[23, 11,29]

Original list:[23, 11,29]

Replicated list:[23,11,29,23,11,29]

Sorted in ascending :[11,11,23,23,29,29]


Sorted in descending:[29,29,23,23,11,11]

Result:

Thus the above python program was executed and output verified.
10. program to count the frequency of the given element in a list of numbers.

Aim:

To write a python a program to count the frequency of the given element in a list of
numbers.

Program:
Ist=eval(input(“enter list :”))

length =len(lst)

element =int(input(“enter element:”)

count=0

for i in range (0,length):

if element==lst[i]:

count+=1
if count==0

print(element,”not found in given list”)

else:

print (element, “has frequency as”,count,”in given list”)

Output:

Enter a list :[1,1,1,2,2,3,4,2,2,5,5,2,2,5]

Enter element:2

2 has a frequency as 6 in given list.

Result:

Thus the above python program was executed and output verified.
11.write a program to input two lists and display the maximum element from the elements of
both the lists combined , along with its index in its list.

Aim:

To write a python program to input two lists and display the maximum element from the
elements of both the lists combined , along with its index in its list.

Program:

lst1=eval(input(“enter list1:”))
lst2=eval(input(“enter list2:”))

mx1=max(lst1)

mx2=max(lst2)

if mx1>=mx2:

print(mx1,”the maximum value is in list1 at index”,lst .index (mx1))

else:

print(mx2,”the maximum value is in list2 at index”, lst2.index(mx2))

Output:

Enter list1:[6,8,11,6,12,7,16]

Enter list2:[34,11,23,11]

34 is the maximum value is in the list2 at index 0

Result:

Thus the above python program was executed and output verified.
12.writ a program to input a tuple and check if it contains the all elements as same.

Aim:

To write a python program to input a tuple and check if it contains the all elements as
same.

Program:
tup=eval(input(“enter a tuple:”))

ln=len(tup)

num=tup.count(tup[0])

if num==ln:

print(“tuple contai9ns all the same elements.”)

else:

print(“tuple contains different elements.”)

Output:

Enter a tuple :23,23,23,23

Tuple contains all the same elements.

Result:

Thus the above python program was executed and output verified.
13. writ a program to check if the elements in the first half of an tuple are sorted in ascending
order or not.

Aim:

To write a python program to check if the elements in the first half of an tuple are
sorted in ascending order or not.

Program:

tup=eval(input(“enter a tuple:”))
ln =len(tup)

mid=ln//2

if ln%2==1:

mid=mid+1

half=tup[:mid]

if sorted (half)==list(tup[:mid]):

print(“first half is sorted”)


else:

print(“first half is not sorted”)

Output:

Enter a tuple:11,22,13,14,10

First half is sorted .

Enter a tuple:11,22,13,14,10

First half is not sorted.

Result:
Thus the above python program was executed and output verified.
14. write a program a to check if the minimum elements of a tuple lies at the middle position
of the tuple .

Aim:

To write a python program a to check if the minimum elements of a tuple lies at the
middle position of the tuple .

Program:

tup=eval(input(“enter a tuple”))

ln=len(tup)
lies=false

mn=min(tup)

if ln%2==0:

half=ln//2

if mn==tup[half] or mn==tup[half-1]:

lies=true

else:
half=ln//2

if mn==tup[half]:

lies=true

if lies==true:

print(“minimum lies at tuple’s middle.”)

else:

print(“minimum doesn’t lie at tuple’s middle.”)

Output:

Enter a tuple:6,7,12,13,5,11,13,8,13

Minimum lies at tuple’s middle.

Result:

Thus the above python program was executed and output verified.
15. write a program to input names of n students and store them in a tuple .also, input a name
from the user and find if this students is present in the tuple or not .

Aim:

To write a python program to input names of n students and store them in a tuple
.also, input a name from the user and find if this students is present in the tuple or not .

Program:

lst=[]

n=int(input(“how many students?”))

for I in range (1,n+1):


name=input(“enter name of student”str(i)+”:”)

lst.append(name)

ntuple=tuple(lst)

nm=input(“enter name to be searched for :”)

if nm in tuple:

tuple(nm, ”exists in the tuple”)

else:
print(nm, “does not exist in the tuple”)

Output:

How many students?5

Enter a name students1: anaya

Enter a name students2:Anusha

Enter name of students3:kirat

Enter a name of students4:kyle:

Enter a name of students5:suji.


Enter name to be searched for: suji

Suji exists in the tuple.

Result:
Thus the above python program was executed and output verified.
16.write a program to delete the keys of a dictionary, one of in LIFO order. Make sure that
there is no error generated after the last item delete.

Aim:

To write a python program to delete the keys of a dictionary, one of in LIFO order. Make
sure that there is no error generated after the last item delete.

Program:

stu={1:’neha’,2: ‘saima’,3: ‘avnit’, 4: ‘ana’, 5: ‘shaji’}


while len (stu)>=1:

print(“Element deleted :”, stu. Popitem())

print(“all elements of the dictionary got deleted in LIFO order”.)

Output:

Element deleted: (5, ‘shaji’)


Element deleted: (4, ‘ana’)

Element deleted: (3, ‘avnit’)

Element deleted: (2, ‘saima’)

Element deleted: (1, ’neha’)

All elements of the dictionary got deleted in LIFO order.

Result:

Thus the above python program was executed and output verified.
17. write a program to print the maximum, minimum, sum of keys of numbers dictionary as
given below

Numbers ={1:111,2:222,3:333,4:444}
also individually find minimum, maximum, sum of values

Aim:

To write a python program to print the maximum, minimum, sum of keys of numbers
dictionary as given below

Numbers ={1:111,2:222,3:333,4:444}
also individually find minimum, maximum, sum of values.

Program:

numbers ={1:111,2:222,3:333,4:444}

print(“given dictionary is:”,numbers)

max_key_val=max(numbers)

min_key_val=min(numbers)
print(“maximum and minimum keys:”,ma_key_val, min_)key_val)

max_value=max(numbers.values())

min_value=min(numbers.values())

print(“maximum and minimum values:”, max_value,min_value)

key_sum=sum(numbers)

values_sum=sum(number.values())

print(“sum of dictionary’s keys:”, key_sum)


print(“sum of dictionary’s values:”,values_sum)

Output:

Given dictionary is :{1: 111, 2: 222, 3: 333, 4: 444}

Maximum and minimum keys:4 1

Maximum and minimum values :444 111

Sum of dictionary’s keys:10

Sum of dictionary’s values:1110


Result:
Thus the above python program was executed and output verified.
18. write a program to create a dictionary name the Dct with 10 keys 0..9, each having values
has 200. Update the first and the last values by adding 200 to each of them.

Aim:

To write a python program to create a dictionary name the Dct with 10 keys 0..9, each
having values has 200. Update the first and the last values by adding 200 to each of them.

Program:

dct=dict.fromkeys(range(10),200)
dct[0]+=200

dct[9]+=200

print(dct)

Output:

{0: 400, 1: 200, 2: 200, 3: 200, 4: 200, 5: 200, 6: 200, 7: 200, 8: 200, 9: 400}

Result:
Thus the above python program was executed and output verified.
19. write a program to read a sentence and then createa dictionary contains the frequency of
letters and digits in the sentence.ignore other symbols,if any.

Aim:

To write a python program to read a sentence and then create dictionary contains the
frequency of letters and digits in the sentence.ignore other symbols,if any.

Program:

sen= input(“enter a sentence :”)


sen=sen.lower()

alphabet_digits=”abcdefdghijklmnopqrstuvwxyz0123456789”

char_count={}

print(“total characters in the sentence are:”, len(sen))

for char in sen:

if char in alphabet_digits:

if char in char_count:
char_count[char]=char_count[char]+1

else:

char_count[char]=1

print(char_count)

Output:

Enter a sentence : hello there! Class 10 is done and now you are in class 11
Total characters in the sentence are:58

{‘h’: 2, ‘e’: 5, ‘l’: 4, ‘o’: 4 ‘t’:1 ‘r’: 2, ‘c’:2, ‘a’: 4 ‘s’: 5 ‘1’:3, ‘0’: 1, ‘i’: 2, ‘d’:2, ‘n’:4, ‘w’:1
,’y’:1,’u’:1}

Result:
Thus the above python program was executed and output verified.
20.write a python program to find the highest 2 values in a dictionary

Aim:

To write a python program to find the highest 2 values in a dictionary

Program:

numbers={31:111,22:222, 43: 333,14:444, 25:555}

s=sorted (numbers.values())

print(“given dictionary is:”numbers)

print(“highest two values of given dictionary are:”,s[-1], s[-2])

Output:
Given dictionary is {31:111, 22:222, 43:333,14:444, 25:555}

Highest two values of the given dictionary are :555 444

Result:
Thus the above python program was executed and output verified.

You might also like