Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

BRIGHT RIDERS SCHOOL

Post Box No. 39665, Abu Dhabi, UAE

ACADEMIC YEAR : 2022-23

CBSE ROLL NO : 27115574

NAME : Jeetamitra Nayak

CLASS : XI – E (BOYS)

SUBJECT : COMPUTER SCIENCE

SUB CODE : 083


BRIGHT RIDERS SCHOOL
Post Box No. 39665, Abu Dhabi, UAE

CERTIFICATE

This is to certify that Cadet Jeetamitra Nayak CBSE Roll No:27115574 has
satisfactorily completed the laboratory work in COMPUTER SCIENCE (083) Python laid down
in the regulations of CBSE for the purpose of AISSCE Practical Examination _________
in Class XI to be held in Bright Riders School, Abu Dhabi on______________.

(Ms.Nithya)
PGT for Computer Science

Examiners:
1 Name:Ms.Nithya Signature:
(Internal)

INDEX
S.NO DATE PROGRAMS PAGE NO SIGNATURE

PYTHON PROGRAMS
Python program to Input two numbers and display
1. 1 28/1/23 the larger and smaller number. 4
Python program to Input three numbers and display
2. “ the largest / smallest number. 5
Write a program to input the value of x and n and
3. “ print the sum of the following series: 7
1+x+x2+x3+x4+ ............xn
Write a program to find the sum of following series
4. “ x + x2/2 + ……….xn/n 8
Python program to Determine whether a number is
5. “ a perfect number. 8
Python program to Determine whether a number is
6. “ an Armstrong number. 9
Python program to Determine whether a number is
7. “ a palindrome. 9
Python program to Input a number and check if the
8. “ number is a prime or composite number. 10

Python program to Display the terms of a Fibonacci


9. “ series. 10

Python program to Compute the greatest common


10. “ multiple common divisor and least of two integers. 11

Python program to Count and display the number of


vowels, consonants, uppercase, lowercase
11. “ 12
characters in string.

Python program to Input a string and determine


12. 2 “ whether it is a palindrome or not. 12
Generate the pattern using the nested loop:

13. “ 13

Write a python program to find the largest/smallest


14. “ number in a list. 13
Write a python program to input a list of numbers
15. “ and swap elements at the even location with the 14
elements at the odd location.
Write a python program to add the integers in a list
16. “ and display the sum. 14

Write a python program that displays options for


inserting or deleting elements in a list. If user
17. “ chooses a deletion option, display a submenu and 15
ask if element is to be deleted with value or by using
its position or a list slice is to be deleted.
Write a python program to input names of n students
and store them in a tuple. Also input a name from
18. “ 17
the user and find if this student is present in the tuple
or not.
Write a python program to find the largest/smallest
19. “ number in a Tuple. 18

Write a python program to add the integers in a


20. “ Tuple and display the sum. 19

Write python program to search for the given


21. “ element in the tuple. 19

Write a python program to find the highest two


22. “ values in a dictionary 20

Write a Python program to sort a dictionary by key.


23. “ 20

Write a Python program to print a dictionary where


24. “ the keys are numbers between 1 and 15 (both 20
included) and the values are square of keys.
1. Python program to Input two numbers and display
the larger and smaller number.

CODING:

Number1 = int(input("Enter any number1:- "))


Number2 = int(input("Enter any number2:- "))

if Number1 > Number2:


print(Number1 ,"is greater than number", Number2)
else:
print(Number2 ,"is greater than number", Number1)

OUTPUT:
Enter any number1:- 2
Enter any number2:- 3
3 is greater than number 2
2. Python program to Input three numbers and display
the largest / smallest number.

CODING:

Number1 = int(input("Enter any number1:- "))


Number2 = int(input("Enter any number2:- "))
Number3 = int(input("Enter any number3:- "))

if Number1 > Number2 > Number3:


print(Number1 ,"is greatest,",Number3,"is the smallest")
elif Number1 > Number3 > Number2:
print(Number1 ,"is greatest,",Number2,"is the smallest")
elif Number2 > Number3 > Number1:
print(Number2 ,"is greatest,",Number1,"is the smallest")
elif Number2 > Number1 > Number3:
print(Number2 ,"is greatest,",Number3,"is the smallest")
elif Number3 > Number1 > Number2:
print(Number3, "is greatest,", Number2, "is the smallest")
elif Number3 > Number2 > Number1:
print(Number3, "is greatest,", Number1, "is the smallest")

OUTPUT:
Enter any number1:- 5
Enter any number2:- 1
Enter any number3:- 7
7 is greatest, 1 is the smallest
3) Write a program to input the value of x and n and print
the sum of the following series:
1+x+x2+x3+x4+ ............xn

CODING:
x = float (input("Enter value of x:- "))
n = int (input ("Enter value of n:-"))
s = 0
for a in range (n + 1) :
s+= x**a
print ("Sum of Series:- ",s)

OUTPUT:

Enter value of x:- 4


Enter value of n:-5
Sum of Series:- 1365.0
4) Write a program to find the sum of following series
x+x^2/2 … x^n/n

CODING:
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))

sum = 0
m = 1

for i in range(1, n) :
fact = 1
for j in range(1, i+1) :
fact *= j
term = x ** i / fact
sum += term * m
m = m * -1

print("Sum =", sum)

OUTPUT:
Enter the value of x: 5
Enter the value of n: 6
Sum = 13.333333333333332

5) Python program to Determine whether a number is a perfect


number.
CODING:

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


cnt = 0
for i in range(1, n):
if n % i == 0:
cnt += i
if cnt == n:
print(n, " is perfect number")
else:
print(n, " is not a perfect number")
Output:
Enter a number to check:7
7 is not a perfect number
6) Python program to Determine whether a number is an
Armstrong number.

CODING:
n=int(input("Enter a number to check:"))
temp = n
cnt=0
while temp > 0:
digit = temp % 10
cnt += digit ** 3
temp //= 10
if n == cnt:
print(n, "is an Armstrong number")
else:
print(n, "is not an Armstrong number")

OUTPUT:
Enter a number to check: 6
6 is not an Armstrong number

7) Python program to Determine whether a number is a


palindrome.

CODING:
n=int(input("Enter a number to check:"))
rev=0
temp = n
while n > 0:
dig = n % 10
rev = rev * 10 + dig
n = n // 10
if temp == rev:
print(temp, "The number is a palindrome!")
else:
print(temp, "The number isn’t a palindrome!")

OUTPUT:
Enter a number to check:6
6 The number is a palindrome!
8) Python program to Input a number and check if the number is
a prime or composite number.

CODING:
num=int(input("enter a number "))
if num>1:
for x in range(2,num):
if num%x == 0:
print("composite number")
break
else:
print("prime number")
elif num<0:
print("negative numbers cannot be determined if prime or composite")
else:
print("neither prime nor composite")

OUTPUT:
enter a number 6
composite number

9) Python program to Display the terms of a Fibonacci series.

CODING:
nterms = int(input("Enter number of terms to display:"))

n1, n2 = 0, 1
count = 0

if nterms <= 0:
print("Please enter a positive integer")

elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1,end=" ")

else:
print("Fibonacci sequence:")
while count < nterms:
print(n1, ",", end=" ")
nth = n1 + n2

n1 = n2
n2 = nth
count += 1

OUTPUT:
Enter number of terms to display:7
Fibonacci sequence:
0 , 1 , 1 , 2 , 3 , 5 , 8 ,

10) Python program to Compute the greatest common multiple


common divisor and least of two integers.

CODING:
num1 = int(input('Enter your first number: '))
num2 = int(input('Enter your second number: '))
def compute_lcm(x, y):

# choose the greater number


if x > y:
greater = x
else:
greater = y

while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1

return lcm
print("The L.C.M. is", compute_lcm(num1, num2))

OUTPUT:
Enter your first number: 6
Enter your second number: 4
The L.C.M. is 12
11) Python program to Count and display the number of vowels,
consonants, uppercase, lowercase characters in string.

CODING:
txt = input("Enter Your text : ")
v = c = uc = lc = 0
v_list = ['a','e','i','o','u','A','E','I','O','U']
for i in txt:
if i in v_list:
v += 1
if i.isalpha():
if i not in v_list:
c += 1
if i.isupper():
uc += 1
if i.islower():
lc += 1
print("Number of Vowels in this text = ", v)
print("Number of Consonants in this text = ", c)
print("Number of Uppercase characters in this text = ", uc)
print("Number of Lowercase characters in this text = ", lc)

OUTPUT:

Enter Your text : I got an apple


Number of Vowels in this text = 5
Number of Consonants in this text = 6
Number of Uppercase characters in this text = 1
Number of Lowercase characters in this text = 10

12) Python program to Input a string and determine whether it


is a palindrome or not.

CODING:
a=(input("enter the string"))
b=str(a)
c=b[::-1]
if(b==c):
print("it is a palindrome")
else:
print("not a palindrome")

OUTPUT: -
enter the string ONLINE CLASS IS BETTER
not a palindrome

13) Generate the pattern using the nested loop

rows = 5
for i in range(0, rows):
# nested loop for each column
for j in range(0, i + 1):
# print star
print("*", end=' ')
# new line after each row
print("\r")

OUTPUT:-

*
**
***
****
*****

14) Write a python program to find the largest/smallest number


in a list.

CODING:-
lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is
:", min(lst))
OUTPUT:-
How many numbers: 5
Enter number 1
Enter number 2
Enter number 3
Enter number 4
Enter number 4
Maximum element in the list is : 4
Minimum element in the list is : 1

15) Write a python program to input a list of numbers and swap


elements at the even location with the elements at the odd
location.

CODING:-
val=eval(input("Enter a list "))
print("Original List is:",val)
s=len(val)
if s%2!=0:
s=s-1
for i in range(0,s,2):
val[i],val[i+1]=val[i+1],val[i]
print("List after swapping :",val)

16) Write a python program to add the integers in a list and


display the sum.

CODING:-
lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Sum of elements in given list is :", sum(lst))
OUTPUT:-

How many numbers: 3


Enter number 1
Enter number 2
Enter number 3
Sum of elements in given list is : 6

17) Write a python program that displays options for inserting


or deleting elements in a list. If 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.

CODING:-

n = int(input("Enter the number of elements that are to be input: "))


print()
l = list()
for i in range(n):
x = eval(input("Enter the element: "))
l.append(x)
print()
print()
print(l, "is your given list.")
print()
print("Would you like to remove an element by:")
print("1. Stating the exact value.")
print("2. Stating its position. ")
c = int(input("Enter your choice: "))
print()
if c == 1:
y = eval(input("Enter the element that you'd like to remove: "))
print()
if y in l:
l.remove(y)
print("The element has been removed.")
else:
print("No such element.")
elif c == 2:
ne = len(l)
print("Index positions are from 0 - ", n - 1)
y = int(input("Enter the index position of the element you'd like to remove:
"))
l.pop(y)
print()
print("The element has been removed.")

OUTPUT:-

Enter the number of elements that are to be input: 6

Enter the element: 1

Enter the element: 2

Enter the element: 3

Enter the element: 4

Enter the element: 5

Enter the element: 6

[1, 2, 3, 4, 5, 6] is your given list.

Would you like to remove an element by:


1. Stating the exact value.
2. Stating its position.
Enter your choice: 1
Enter the element that you'd like to remove: 1

The element has been removed.

18) 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 student is present in the tuple or not.

CODING:-

n = int(input("Enter the number of students: "))


list1 = []
for i in range(n):
name = input()
list1.append(name)
# makes a tuple from the list of names
tuple1 = tuple(list1)
findName = input("Enter name to find: ")
# part (a) a user defined function to search
def userDefinedSearch():
#loops through every element of tuple
for item in tuple1:
#if any element is equal to what we are finding
if item==findName:
#announce item found
print("Name found")
return #return from the function
#this statement is reached only if the element is not found
print("Name not found")

#calling user defined function


userDefinedSearch()

# part (b) built in function


# index() returns the first index where element is found
# the return value will be either 0 or more than 0 if the element is present in
the tuple
if tuple1.index(findName) >=0 :
print("Name found")
else:
print("Name not found")

OUTPUT:-
Enter the number of students: 8
1
2
3
4
5
6
7
8
Enter name to find: 3
Name found
Name found

19) Write a python program to find the largest/smallest number in a Tuple.

CODING:-
lgsmTuple = (78, 67, 44, 9, 34, 88, 11, 122, 23, 19)
print("Tuple Items = ", lgsmTuple)

print("Largest Item in lgsmTuple Tuple = ", max(lgsmTuple))


print("Smallest Item in lgsmTuple Tuple = ", min(lgsmTuple))
OUTPUT:-
Tuple Items = (78, 67, 44, 9, 34, 88, 11, 122, 23, 19)
Largest Item in lgsmTuple Tuple = 122
Smallest Item in lgsmTuple Tuple = 9

20) Write a python program to add the integers in a Tuple and display the sum.

CODING:-
t = list()

n = int(input('Enter the number of elements for the tuple: '))

print('Enter the elements...')

for i in range(n):

t.append(int(input('>> ')))

t = tuple(t)

s = sum(t)
print('Given tuple:', t)

print('Sum of elements:', s)

OUTPUT:-

Enter the number of elements for the tuple: 6


Enter the elements...
>> 1
>> 2
>> 3
>> 4
>> 5
>> 5
Given tuple: (1, 2, 3, 4, 5, 5)
Sum of elements: 20

21) Write python program to search for the given element in the tuple.

CODING:-

n = int(input("Enter the number of students: "))


list1 = []
for i in range(n):
name = input()
list1.append(name)
# makes a tuple from the list of names
tuple1 = tuple(list1)
findName = input("Enter name to find: ")
# part (a) a user defined function to search
def userDefinedSearch():
#loops through every element of tuple
for item in tuple1:
#if any element is equal to what we are finding
if item==findName:
#announce item found
print("Name found")
return #return from the function
#this statement is reached only if the element is not found
print("Name not found")

#calling user defined function


userDefinedSearch()

# part (b) built in function


# index() returns the first index where element is found
# the return value will be either 0 or more than 0 if the element is present in
the tuple
if tuple1.index(findName) >=0 :
print("Name found")
else:
print("Name not found")

OUTPUT:-
Enter the number of students: 6
1
2
3
4
5
6
Enter name to find: 6
Name found

22) Write a python program to find the highest two values in a dictionary

CODING:-

# create a new Dictionary


dict1 ={"windows":13, "linux":3, "unix":6, "android":11}
# values() returns the list of values in the Dictionary
# sorted() will sort the list of values in ascending order
list1 = sorted(dict1.values())
# the second last element of the list is the second largest because the list is in
ascending order
secondLargest = list1[-2]
print("Second largest element found = ",secondLargest)

OUTPUT:-
Second largest element found = 11

23) Write a Python program to sort a dictionary by key.

CODING:-
color_dict = {'red': '#FF0000',
'green': '#008000',
'black': '#000000',
'white': '#FFFFFF'}

for key in sorted(color_dict):


print("%s: %s" % (key, color_dict[key]))

OUTPUT:-

black: #000000
green: #008000
red: #FF0000
white: #FFFFFF

24) Write a Python program to print a dictionary where the keys are numbers between 1 and 15 (both
included) and the values are square of keys.
CODING:-

d = dict()
for x in range(1, 16):
d[x] = x ** 2
print(d)

OUTPUT:-
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196,
15: 225}

You might also like