0% found this document useful (0 votes)
2 views16 pages

Class Xi Computer Science Practical Programs

The document outlines a list of computer science practical exercises for Class XI at JSS Public School, Bengaluru for the academic year 2022-23. It includes various programming tasks such as input/output operations, arithmetic calculations, pattern generation, series summation, and data structure manipulations. Each task is accompanied by example code snippets and expected outputs.
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)
2 views16 pages

Class Xi Computer Science Practical Programs

The document outlines a list of computer science practical exercises for Class XI at JSS Public School, Bengaluru for the academic year 2022-23. It includes various programming tasks such as input/output operations, arithmetic calculations, pattern generation, series summation, and data structure manipulations. Each task is accompanied by example code snippets and expected outputs.
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

JSS PUBLIC SCHOOL (SENIOR SECONDARY)

HSR LAYOUT – BENGALURU – 560102


COMPUTER SCIENCE PRACTICALS LIST (2022-23)
CLASS: XI
1 Input a welcome message and display it.
greeting_message=input("Enter the Welcome message::")
print("The Message you entered is::",greeting_message)
OUTPUT:

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


num1=int(input("Enter First Number:"))
num2=int(input("Enter Second Number:"))
if (num1>num2):
print("First Number is Larger than Second Number:")
elif(num1==num2):
print("Both the numbers are equal:")
else:
print("Second Number is Larger than First Number:")

OUTPUT

3 write a program to enter two integers and perform all arithmetic operations on them.
x=int(input("Enter First Integer:"))
y=int(input("Enter Second Integer:"))
summ=x+y
diff=x-y
mult=x*y
div=x/y
mod=x%y
print("Numbers are",x,y)
print("Sum is=",summ)
print("Difference is =",diff)
print("Multiplication is=",mult)
print("Division is=",div)
print("Modulation is=",mod)
OUTPUT

1
4 Generate the following patterns using nested loop.

#PATTERN 1
n = int(input("Enter the number of rows: ")) OUTPUT

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


for j in range(i):
print("*", end="")
print()

#PATTERN 2
n=int(input("Enter No of Rows:")) OUTPUT
for i in range(n):
for j in range(n-i):
print(j+1, end='')
print()

#PATTERN 3
n=int(input("Enter No of Rows:")) OUTPUT
for i in range(n):
for j in range(i+1):
print(chr(65+j), end='')
print()

2
5 Write a program to input the value of x and n and print the sum of the following series:

# 1. series of
x = int(input("Enter the value of x: ")) OUTPUT
n = int(input("Enter the value of n: "))

sum = 1

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


sum = sum + x**i
print("Sum =", sum)

# 2. Series of
x = int(input("Enter the value of x: ")) OUTPUT
n = int(input("Enter the value of n: "))

sum = 1

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


if i % 2 == 0:
sum = sum + x**i
else:
sum = sum - x**i

print("Sum =", sum)

# 3. series of
x = int(input("Enter the value of x: ")) OUTPUT
n = int(input("Enter the value of n: "))

sum = x

for i in range(2, n + 1):


if i % 2 == 0:
sum = sum - (x**i) / i
else:
sum = sum + (x**i) / i

print("Sum =", sum)

# 4. series of
import math OUTPUT
x = float (input('Enter value of x :'))
n= int (input ('Enter value of n :'))
sum=x
for i in range (2,n+1):
3
if (i%2==0):
sum=sum+((x**i)/[Link](i))
else:
sum=sum-((x**i)/[Link](i))
print ('Sum is:', sum)

6 Determine whether a number is a perfect number, an Armstrong number or a palindrome.


(371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.)
(A Perfect Number “n”, is a positive integer which is equal to the sum of its factors, excluding “n” itself.)
1#Determine whether a number is a perfect number
n = int(input("Enter any number: ")) OUTPUT
sum = 0
i=1
for i in range(1, n):
if(n % i == 0):
sum = sum + i
if (n == sum):
print("The number is a Perfect number!")
else:
print("The number is not a Perfect number!")

2#Finding Armstrong Number OUTPUT


n1 = int(input("Enter any number: "))
temp=num=n1
no_of_digits=0
while(num!=0):
no_of_digits+=1
num=int(num/10)
print("No of digits is:", no_of_digits)
#Sum of the digits power raise to no of digits
sum=0
while(n1!=0):
last_digit=n1%10
sum+=(last_digit**no_of_digits)
n1=int(n1/10)
#Checking Armstrong Number
if(sum==temp):
print("Number is Armstrong number")
else:
print("Number is Not Armstrong number")

3#Finding Palindrome or Not OUTPUT


n=int(input("Enter the Number:"))
rev=0
temp=n
while(n!=0):
last_digit=n%10
rev=rev*10+last_digit
4
n=n//10
if(temp==rev):
print("It is Palindrome Number")
else:
print("It is not a Palindrome Number")

7 Input a number and check if the number is a prime or composite number.


n=int(input("Enter any number::")) OUTPUT
if(n==0 or n==1):
print("Number is neither Prime not
Composite")
elif(n>1):
for i in range(2,n):
if(n%i==0):
print("Number is not Prime but
Composite")
break
else:
print("Number is Prime number but not
Composite")
else:
print("Please enter positive integer
number")

8 Display the terms of a Fibonacci series.


#Display the terms of a Fibonacci series.
n1=0
n2=1
terms=int(input("Enter the Terms of Fibonacci series you want to print::"))
if terms<=0:
print("Enter positive value of term.")
else:
if terms==0:
print(n1,end=" ")
else:
print(n1,n2, end=" ")
for i in range(2,terms):
next_term=n1+n2
print(next_term, end=" ")
n1=n2
n2=next_term

OUTPUT

5
9 Compute the greatest common divisor and least common multiple of two integers.
#Compute the greatest common divisor and least common multiple of two integers.
num1=int(input("Enter First Number:"))
num2=int(input("Enter Second Number:"))
gcd=1
if num1%num2==0:
gcd=num2
else:
for k in range(num2//2,1,-1):
if num1%k==0 and num2%k==0:
gcd=k
break
lcm=(num1*num2)/gcd
print("GCD is:",gcd)
print("LCM is:",lcm)

OUTPUT

10 Count and display the number of vowels, consonants, uppercase, lowercase characters in string.
#Count and display the number of vowels, consonants, uppercase, lowercase characters in string.
str=input("Enter the String::\n")
vowels=0
consonants=0
for i in str:
if (i=='a'or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O'or i=='U'):
vowels=vowels+1
else:
consonants=consonants+1
print("The number of vowels:", vowels)
print("The number of Consonants:", consonants)

#UPPERCASE and LOWERCASE LOGIC


#str1=input("Enter the String::\n")

6
upper=0
lower=0
for i in range(len(str)):
if(str[i]>='a' and str[i]<='z'):
lower+=1
elif(str[i]>='A' and str[i]<='z'):
upper+=1
print('Lower case letters=',lower)
print('Upper case letters=',upper)

OUTPUT

11 Input a string and determine whether it is a palindrome or not; convert the case of characters in a
string.
original=input("Enter a string:") OUTPUT
reverse=original[::-1] #[::-1} will reverse the
string
#print("Reverse String=",reverse)
if original==reverse:
print("String is Palindrome:")
else:
print("String is not Palindrome:")
12 Find the largest/smallest number in a list/tuple
lst=[12,34,43,67,33,3,10] OUTPUT:
length=len(lst)
[Link]()
print("Largest element is:",lst[length-1])
print("Smallest element is:", lst[0])
print("Second Largest element is:",lst[length-2])
print("Second smallest element is:", lst[1])

13. Input a list of numbers and swap elements at the even location with the elements at the odd location.
#Code to get list from user OUTPUT:
L=[]
N=int (input("Enter the size of the list:"))
print("Enter the elements one oby one:")
for i in range(N):
Element=int(input("->"))
[Link](Element)
print("The given List is:")
print(L)

7
# swap the elements at even location with the
elements at odd location
for i in range(0,N,2):
temp1=L[i]
temp2=L[i+1]
L[i]=temp2
L[i+1]=temp1
print("\n The List after swaping is:")
print(L)

14. Input a list/tuple of elements, search for a given element in the list/tuple.
lst=[] OUTPUT:
num=int(input("How many Numbers in the lsit:"))
for n in range(num):
numbers=int(input("Enter Number:"))
[Link](numbers)
print("The Entered list is:",lst)
length=len(lst)
element=int(input("Enter the element to be searched for:"))
for i in range(0,length):
if element==lst[i]:
print(element,"found at index",i,"and position:",i+1)
break
else:
print(element, "is not found!!!")

15. Input a list of numbers and find the smallest and largest number from the list.
#Method 1 OUTPUT:
lst=[]
num=int(input("How many numbers:"))
for n in range(num):
numbers=int(input("Enter Number"))
[Link](numbers)
print("Maximum elements in the list is:",max(lst))
print("\n Minimum element in the list is:",min(lst))

#Method 2
print("\n By Method 2:\n")
[Link]()
print("Maximum element in the list is:",lst[num-1])
print("\n Minimum element inthe list is:",lst[0])

16. Create a dictionary with the roll number, name and marks of n students in a class and display the names of
students who have scored marks above 75.
n=int(input("Enter Number of students:")) OUTPUT:
result={}
for i in range(n):
print("Enter Details of Student No:")
rno=int(input("Enter Roll NO:"))
name=input("Enter Name:")
marks=float(input("Enter Marks:"))

8
result[rno]=[name,marks]
print(result)
#Display names of students who have got marks
more than 75
for student in result:
if result[student][1]>75:
print(result[student][0])

17 Create a dictionary named student and write a menu-driven program to do the following.
. 1. Show record
2. Add new student
3. Delete a student
4. Search record
5. Update record
6. Sort record
7. Exit
n=int(input("How many stduents:"))
std={}
for i in range(n):
print("Enter details of student:",i+1)
name=input("Enter name of student:")
pn=int(input("Enter Percentage:"))
std[name]=pn
c=0
while c!=7:
print(''
1. Show record
2. Add new student
3. Delete a student
4. Search record
5. Update record
6. Sort record
7. Exit
'')
c=int(input("Enter your choice:"))
if c==1:
for i in std:
print(i,":",std[i])
elif c==2:
print("Enter details of new student:")
name=input("Enter name:")
pn=int(input("Enter Percentage:"))
std[name]=pn
elif c==3:

9
nm=input("Enter name to be deleted:")
f=[Link](nm,-1)
if f!=-1:
print(f, " is deleted successfully.")
else:
print(f, " not found.")
elif c==4:
name=input("Enter Customer Name:")
if name in std:
print(name, " found in the record.")
else:
print(name, " not found in the record.")
elif c==5:
name=input("Enter Customer Name:")
pn=int(input("Enter percentage to modify:"))
std[name]=pn
elif c==6:
l=sorted(std)
for i in l:
print(i,":",std[i])
elif c==7:
break
else:
print("Invalid Choice")

OUTPUT:

18. Write a program to choose any 4 customers randomly for lucky winners out of 100 customers.
import random
c1=[Link](1,100)
c2=[Link](1,100)
10
c3=[Link](1,100)
c4=[Link](1,100)
print("Lucky winners are:",c1,c2,c3,c4)

OUTPUT:

19. Write a menu-driven program to perform these operations by importing string module.
1. Display the ascii letters
2. Display the digits
3. Display Hexadedigits
4. Display Octdigits
5. Display Punctuation
6. Display the first letter of each word into capital by removing spaces
import string
ch=0
while ch!=7:
print('''
1. Display the ascii letters
2. Display the digits
3. Display Hexadedigits
4. Display Octaldigits
5. Display Punctuation
6. Display string in title case
7. Exit
''')
ch=int(input("Enter your choice:"))
if ch==1:
print(string.ascii_letters)
elif ch==2:
print([Link])
elif ch==3:
print([Link])
elif ch==4:
print([Link])
elif ch==5:
print([Link])
elif ch==6:
s=input("Enter sentence:")
print([Link](s))
elif ch==7:
break

OUTPUT:

11
20. Write a program to input your friends’ names and their Phone Numbers and store them in the dictionary as the
key-value pair. Perform the following operations on the dictionary.
(a) Display the name and phone number of all your friends.
(b) Add a new key-value pair in this dictionary and display the modified dictionary.
(c) Delete a particular friend from the dictionary.
(d) Modify the phone number of an existing friend
(e) Check if a friend is present in the dictionary or not.
(f) Display the dictionary in sorted order of names.
n=int(input("How many friends?"))
fd={}
for i in range(n):
print("Enter details of Friend:",(i+1))
name=input ("Name:")
ph=int(input("Phone:"))
fd[name]=ph
print("Friends dictionary is",fd)
ch=0
while ch!=7:
print("\t MENU")
print("1. Display all Friends")
print("2. Add a new Friend")
print("3. Delete a Friend")
print("4. Modify a Phone Number")
print("5. Search for a Friend")
print("6. Sort the Names")
print("7. Exit")
ch=int(input("Enter your choice(1 to 7):"))
if ch==1:
print(fd)
elif ch==2:
print("Enter Deatails of New Friend:")

12
name=input("Name")
ph=int(input("Phone:"))
fd[name]=ph
elif ch==3:
nm=input("Friend Name to be deleted:")
res=[Link](nm,-1)
if res!=-1:
print(res, "Deleted")
else:
print("No Such friend")
elif ch==4:
name=input("Friend Name:")
ph=int(input("Changed Phone:"))
fd[name]=ph
elif ch==5:
name=input("Friend Name:")
if name in fd:
print(name,"Exists in the dictionary.")
else:
print(name,"does not exist in the dictionary..")
elif ch==6:
lst=sorted(fd)
print("{",end='')
for a in lst:
print(a,":", fd[a],end='')
print("}")
elif ch==7:
print("Exited successfully..")
break
else:
print("Valid choices are 1 to 7")

OUTPUT:

13
21. Write a program that displays options for inserting or deleting elements in a list. If the user chooses a deletion
option, display a submenu and ask if element is to be deleted with value or by using its position or a list slice is
to be deleted.
#Write a program that displays options for inserting or deleting elements in a list
val=[17,23,18,19]
print("The list is:",val)
while True:
print("\t Main Menu")
print("1. Insert")
print("2. Delete")
print("3. Exit")
ch=int(input("Enter your choice 1/2/3:"))
if ch==1:
item=int(input("Enter item:"))
pos=int(input("Insert at which position"))
index=pos-1
[Link](index,item)
print("Success!List now is:",val)
elif ch==2:
print("\t Deleting Menu")
print("1. Delete using value")
print("2. Delete using index")
print("3. Delete using a sublist")
dch=int(input("Enter choice (1/2/3):"))
if dch==1:
item=int(input("Enter item to be deleted:"))
14
[Link](item)
print("List now is:",val)
elif dch==2:
index=int(input("Enter index of item to be deleted:"))
[Link](index)
print("List now is:",val)
elif dch==3:
l=int(input("Enter lower limit of list slice to be deleted:"))
h=int(input("Enter upper limit of list slice to be deleted:"))
del val[1:h]
print("List now is:",val)
else:
print("valid choices are 1/2/3 only..")
elif ch==3:
print("Exited Successfully...")
break
else:
print("Valid choices are 1/2/3 only")

OUTPUT:

22. Write a program to read email IDs of a number of students and store them in a tuple. Create two new tuples,
one to store only the usernames from the email IDs and second to store domain names from the email ids. Print
all three tuples at the end of the program. (HINT: you may use the function split())
#Write a program to read email IDs of a number of students and store them in a tuple
lst=[]

15
n=int(input("How many students?"))
for i in range(1,n+1):
email=input("Enter email id of student"+str(i)+":")
[Link](email)
etuple=tuple(lst)
lst1=[]
lst2=[]
for i in range(n):
email=etuple[i].split('@')
[Link](email[0])
[Link](email[1])
unameTup=tuple(lst1)
dnameTup=tuple(lst2)
print("Student email ids:")
print(etuple)
print("User name tuple:")
print(unameTup)
print("Domain name tuple:")
print(dnameTup)

OUTPUT:

16

You might also like