XL C.S Lab Manual 24-25
XL C.S Lab Manual 24-25
SCHOOL
GRADE-XI
COMPUTER SCIENCE WITH
PYTHON LAB MANUAL
Page1
1. Finding largest and smallest number
AIM:
To write a program to input 3 numbers and print the greatest number using
nested if
APROGRAM:
a=float(input("Enter the first number: "))
b=float(input("Enter the second number: "))
c=float(input("Enter the third number: "))
if a>b:
if a>c:
print("First number :",a,"is greatest")
if b>a:
if b>c:
print("Second number :",b,"is greatest")
else:
print("Third number :",c,"is greatest")
Page2
OUTPUT:
Enter the first number4
Enter the second number2
Enter the third number2.1
First number :4.0 is greatest
RESULT:
Thus the above program to input 3 numbers and print the greatest
number using nested if, has been created and executed successfully.
Page3
2. Finding percentage marks of student
AIM:
To write a program to input percentage marks of a student and find the grade
as per mark.
PROGRAM:
Page4
OUTPUT:
Enter the percentage marks: 85
The student has got a B grade
RESULT:
Thus the above program to input percentage marks of a student and find the
grade as per mark has been created and executed successfully.
Page5
3. Checking of Prime or not
AIM:
To write a program to check a number is a prime number or not.
PROGRAM:
num=int(input('Enter the number:'))
for i in range(2,num//2+1):
if num%i==0:
print('It is not a prime number')
break
else:
print('It is a prime number')
Page6
OUTPUT:
Enter the number: 12
It is not a prime number
RESULT:
Thus the program to check a given number is a prime number or not has been
created and executed successfully.
Page7
4.If ..… elif else
AIM:
To write a program to print whether a given character is an uppercase or a
lowercase character or a digit or any other character.
PROGRAM:
ch=input('Enter a single character:')
if ch>='A' and ch<='Z':
print('You have entered an uppercase character.')
elif ch>='a' and ch<='z':
print('You have entered a lowercase character.')
elif ch>='0' and ch<='9':
print('You have entered a digit.')
else:
print('You have entered a special character.')
Page8
OUTPUT:
Enter a single character: c
You have entered a lowercase character.
RESULT:
Thus the program to print whether a given character is an uppercase or a
lowercase character or a digit or any other character has been created and
executed successfully.
Page9
5.Factorial of N Number
AIM:
To write a program to calculate the factorial of a number.
APROGRAM:
n =int(input('Enter a number:'))
fact=1
a=1
while a<=n:
fact*=a
a+=1
print('The factorial of',n,'is',fact)
Page10
OUTPUT:
Enter a number: 5
The factorial of, 5 is 120
RESULT:
Thus the program to calculate the factorial of a number has been created and
executed successfully.
Page11
6. Nested Loop
AIM:
To write a program to create a triangle of stars using nested loop.
PROGRAM:
for i in range(1,6):
print()
for j in range(1,i):
print('*',end=' ')
Page12
OUTPUT:
*
**
***
****
RESULT:
Thus the program to create a triangle of stars using nested loop has been
created and executed successfully.
Page13
7. Fibonacci Series
AIM:
To write a program to print Fibonacci series of first N numbers.
PROGRAM:
N=int(input(“Enter number =”))
first=0
second=1
print(first, end=' ')
print(second,end=' ')
for a in range(1,N):
third=first+second
print(third,end=' ')
first,second=second,third
Page14
OUTPUT:
Enter number N= 11
0 1 1 2 3 5 8 13 21 34 55 89
RESULT:
Thus the program to print Fibonacci series of first N numbers has been created
and executed successfully.
Page15
8. Sum of Series
AIM:
To write a program to find sum of series s=1+x+x ²+x ³+x4…+x ⁿ.
PROGRAM:
Page16
OUTPUT:
Enter the value of x: 2
Enter the value of n (for x**n): 5
Sum of first 5 terms: 63
RESULT:
Thus the program to find sum of series s=1+x+x ²+x ³+x4…+x ⁿ has been
created and executed successfully.
Page17
9. Splitting a given list into even and odd elements list
AIM:
To write a program to split a given list into even and odd elements list.
APROGRAM:
L=[5,6,7,8,9,4,3,2]
el=[]
ol=[]
for i in L:
if i%2==0:
el.append(i)
else:
ol.append(i)
print('even list=',el)
print('odd list=',ol)
Page18
OUTPUT:
even list= [6, 8, 4, 2]
odd list= [5, 7, 9, 3]
RESULT:
Thus the program to split a given list into even and odd elements list has
been created and executed successfully.
Page19
10. Palindrome
AIM:
PROGRAM:
string=input('Enter a string:')
length=len(string)
mid=length//2
rev=-1
for a in range(mid):
if string[a]==string[rev]:
rev = rev - 1
else:
break
else:
print(string,'is a palindrome.')
Page20
OUTPUT:
racecar is a palindrome
RESULT:
Thus the above python program that reads a string and checks whether
it is a palindrome string or not has been created and executed successfully.
Page21
11. STRING FUNCTIONS
AIM:
To write a program that inputs individual words of your school motto and
joins them to make a string. It should also input day, month and year of your
school's foundation date and print the complete date.
PROGRAM:
dd = input("Enter dd:")
mm = input("Enter mm:")
Page22
OUTPUT:
Enter dd:01
Enter mm:05
Enter yyyy:1993
RESULT:
Thus the above program that inputs individual words of your school
motto and joins them to make a string. It should also input day, month and
year of your school's foundation date and print the complete date has been
created and executed successfully.
Page23
12. ARMSTRONG NUMBER
AIM:
PROGRAM:
summ = 0
temp = num
digit = temp % 10
summ += digit ** 3
temp //= 10
if (num == summ):
else:
Page24
OUTPUT:
RESULT:
Page25
13. SEARCHING FOR AN ELEMENT IN A GIVEN LIST
AIM:
PROGRAM:
length = len(list)
if element == list[i]:
break
else:
Page26
OUTPUT:
90 found at index 6
RESULT:
Thus the above python program to search for an element in a given list of
numbers has been created and executed successfully.
Page27
14. UNPACKING TUPLE
AIM:
To write a program to input a 4-element tuple and unpack it to four variables. Then
recreate the tuple with elements swapped as 1st element with 3rd and the 2nd
element with the 4th element.
PROGRAM:
a, b, c, d = tup
tup = c, d, a, b
OUTPUT:
Tuple unpacked in 10 20 30 40
RESULT:
Thus the above python program to input a 4-element tuple and unpack it to
four variables. Then recreate the tuple with elements swapped as 1st element with
3rd and the 2nd element with the 4th element has been created and executed
successfully.
Page28
15. CREATING DICTIONARY
AIM:
PROGRAM:
CompWinners = {}
for a in range(n):
print (CompWinners)
Page29
OUTPUT:
RESULT:
Page30