0% found this document useful (0 votes)
19 views30 pages

XL C.S Lab Manual 24-25

Computer science manual

Uploaded by

patrickappu252
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)
19 views30 pages

XL C.S Lab Manual 24-25

Computer science manual

Uploaded by

patrickappu252
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/ 30

EVERWIN VIDHYASHRAM SR SEC.

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:

a=float(input('Enter the percentage marks:'))


if a>=90:
print('The student has got an A grade')
elif a>=75 and a<90:
print('The student has got a B grade')
elif a>=60 and a<75:
print('The student has got a C grade')
else:
print('The student has got a D grade')

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:

x=float(input('Enter the value of x:'))


n=int(input('Enter the value of n (for x**n):'))
s=0
for a in range(n+1):
s+=x**a
print('Sum of first' ,n,'terms:',s)

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:

To write a program that reads a string and checks whether it is a palindrome


string or not.

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:

print(string,'is not a palindrome.')

break

else:

print(string,'is a palindrome.')

Page20
OUTPUT:

Enter a string: racecar

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:

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 = "".join([w1, w2, w3, w4])

print("Enter your school's 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)

Page22
OUTPUT:

Enter words of your school motto, one by one

Enter word 1: GOOD

Enter word 2: ENGLISH

Enter word 3: GOOD

Enter word 4: MARKS.

Enter your school's foundation date.

Enter dd:01

Enter mm:05

Enter yyyy:1993

School motto: GOOD ENGLISH GOOD MARKS

School foundation date 01/05/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:

To write a program to check if a given number is an Armstrong number or


not.

PROGRAM:

num = int(input("Enter a 3 digit number: "))

summ = 0

temp = num

while (temp > 0):

digit = temp % 10

summ += digit ** 3

temp //= 10

if (num == summ):

print(num, "is an Armstrong number")

else:

print(num, "is Not an Armstrong number"):

Page24
OUTPUT:

Enter a 3 digit number: 407

407 is an Armstrong number

RESULT:

Thus the above python program to check if a given number is an


Armstrong number or not has been created and executed successfully.

Page25
13. SEARCHING FOR AN ELEMENT IN A GIVEN LIST

AIM:

To write a python program to search for an element in a given list of numbers.

PROGRAM:

list = eval(input("Enter list:"))

length = len(list)

element = int(input("Enter element to be searched for: "))

for i in range(0, length):

if element == list[i]:

print(element, "found at index", i)

break

else:

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

Page26
OUTPUT:

Enter list: [2,8,14,56,7,8,90,34,15]

90 found at index 6

Enter element to be searched for: 90

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:

tup = eval(input("Enter a 4 element tuple: "))

a, b, c, d = tup

print("Tuple unpacked in", a, b, c, d)

tup = c, d, a, b

print("Tuple after swapping the elements:", tup)

OUTPUT:

Enter a 4 element tuple: 10,20,30,40

Tuple unpacked in 10 20 30 40

Tuple after swapping the elements: (30, 40, 10, 20)

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:

To write a program to create a dictionary containing names of competition winner


students as keys and number of their wins as values.

PROGRAM:

n=int(input("How many students?"))

CompWinners = {}

for a in range(n):

key = input("Name of the student :")

value = int (input("Number of competitions won :"))

CompWinners [key] = value

print ("The dictionary now is:")

print (CompWinners)

Page29
OUTPUT:

How many students?3

Name of the student: Rohan

Number of competitions won : 8

Name of the student jack

Number of competitions won : 6

Name of the student: Nihar

Number of competitions won : 7

The dictionary now is:

{'Rohan': 8, 'jack': 6, 'Nihar': 7}

RESULT:

Thus the above python program to create a dictionary containing names of


competition winner students as keys and number of their wins as values has
created and executed successfully.

Page30

You might also like