0% found this document useful (0 votes)
31 views17 pages

XI CS Practical List 2023-24

The document is a practical file for Computer Science (083) for Class XI A at Kendriya Vidyalaya Lumding for the session 2023-24. It contains various Python programs that cover topics such as simple interest calculation, number swapping, checking even/odd numbers, arithmetic operations, and more. Each program includes code snippets, user inputs, and outputs demonstrating the functionality of the programs.

Uploaded by

ah8099687515
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)
31 views17 pages

XI CS Practical List 2023-24

The document is a practical file for Computer Science (083) for Class XI A at Kendriya Vidyalaya Lumding for the session 2023-24. It contains various Python programs that cover topics such as simple interest calculation, number swapping, checking even/odd numbers, arithmetic operations, and more. Each program includes code snippets, user inputs, and outputs demonstrating the functionality of the programs.

Uploaded by

ah8099687515
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/ 17

KENDRIYA VIDYALAYA LUMDING

PRACTICAL FILE
COMPUTER SCIENCE (083)
CLASS: XI A
(SESSION: 2023-24)

SUBMITTED BY: ………………………………………

ROLL NO. : ………………………………………

1
Program 1: WAP to input principal amount, rate of interest and time period & calculate simple
interest.
Code:
p=int(input("Enter Principal amount="))
r=float(input("Enter rate of interest="))
t=int(input("Enter time period in years="))
si=(p*r*t)/100
print("Simple Interest=",si)

Output:
Enter Principal amount=5000
Enter rate of interest=6.5
Enter time period in years=6
Simple Interest= 1950.0

Program 2: WAP in python to swap two numbers.


Code:
#Program to swap two numbers
a=int(input("Enter first number"))
b=int(input("Enter first number"))
print("Before swapping the values are=",a,b)
a,b=b,a
print("After swapping the values are=",a,b)

Output:
Enter first number50
Enter first number100
Before swapping the values are= 50 100
After swapping the values are= 100 50

Program 3: WAP in python to check whether a user entered number is even or odd.
Code:
number=int(input("Enter any integer number="))
if number%2==0:
print("The entered number" , number, " is Even")
else:
print("The entered number" , number, " is Odd")

Output:
Enter any integer number=43
The entered number 43 is Odd

Enter any integer number=72


The entered number 72 is Even

2
Program 4: Write a program to display weekday name against a user entered weekday number.
Code:
weekdayno=int(input("Enter day number of week day="))
if weekdayno==1:
print("Monday")
elif weekdayno==2:
print("Tuesday")
elif weekdayno==2:
print("Wednesday")
elif weekdayno==4:
print("Thursday")
elif weekdayno==5:
print("Friday")
elif weekdayno==6:
print("Saturday")
elif weekdayno==7:
print("Sunday")
else:
print("You have entered wrong day number")

Output:
Enter day number of week day=6
Saturday

Enter day number of week day=1


Monday

Program 5: WAP in python to calculate & display the result of a user entered arithmetic operation
done on two user entered numbers.
Code:
num1=int(input("Enter first number="))
num2=int(input("Enter second number, except zero="))
arop=input("Enter arithmetic symbol=")
#For Addition
if arop=='+':
print("The addition of two numbers",num1,num2,"=",num1+num2)
#For subtraction
if arop=='-':
print("The sutraction of two numbers",num1,num2,"=",num1-num2)
#For Product
if arop=='*':
print("The product of two numbers",num1,num2,"=",num1*num2)
#For Quotient
if arop=='/':
print("The quotient of two numbers",num1,num2,"=",num1/num2)

3
#For Floor division
if arop=='//':
print("The quotient in floor division of two numbers",num1,num2,"=",num1//num2)
#For Remainder
if arop=='%':
print("The modulo/remainder of two numbers",num1,num2,"=",num1%num2)
#For Exponent
if arop=='**':
print("The exponentiation of two numbers",num1,num2,"=",num1**num2)

Output:
Enter first number=45
Enter second number, except zero=7
Enter arithmetic symbol=/
The quotient of two numbers 45 7 = 6.428571428571429

Enter first number=45


Enter second number, except zero=7
Enter arithmetic symbol=%
The modulo/remainder of two numbers 45 7 = 3

Program 6: WAP in python to find the largest value among three user entered values.
Code:
a=int(input("Enter first number="))
b=int(input("Enter second number="))
c=int(input("Enter third number="))
max=a
if b>max:
max=b
if c>max:
max=c
print("The largest number is =", max)

Output:

Enter first number=70


Enter second number=80
Enter third number=20
The largest number is = 80

Enter first number=50


Enter second number=10
Enter third number=90
The largest number is = 90

4
Program 7: WAP in python to find the second largest value among three user entered values.
Code:
a=int(input("Enter first number"))
b=int(input("Enter first number"))
c=int(input("Enter first number"))
if a>b and a>c:
max=a
if b>c:
max1=b
else:
max1=c
elif b>c and b>a:
max=b
if a>c:
max1=a
else:
max1=c
else:
max=c
if b>a:
max1=b
else:
max1=a
print("Second largest=",max1)

Output:
Enter first number65
Enter first number25
Enter first number37
Second largest= 37

Program 8: WAP in python to calculate factorial of a user entered number.


Code:
n=int(input("Enter a number"))
fact=1
for i in range(1,n+1):
fact=fact*i
print("factorial of number=",n,"is ",fact)

Output:
Enter a number6
factorial of number= 6 is 720

Program 9: WAP in python to display a table of a user entered number.


Code:
n=int(input("Enter a number"))
for i in range(1,11):
print(n*i,end=" ")

5
Output:
Enter a number9
9 18 27 36 45 54 63 72 81 90

Program 10: WAP in python to display the sum of a range of user entered numbers.
Code:
sn=int(input("Enter starting value of range="))
ln=int(input("Enter last value of range="))
s=0
for i in range(sn,ln+1):
s=s+i
print("Sum=",s)

Output:
Enter starting value of range=1
Enter last value of range=10
Sum= 55

Program 11: WAP in python to display the product of a range of user entered numbers.
Code:
sn=int(input("Enter starting value of range="))
ln=int(input("Enter last value of range="))
p=1
for i in range(sn,ln+1):
p=p*i
print("Product=",p)

Output:
Enter starting value of range=1
Enter last value of range=5
Product= 120

Program 12: WAP in python to display Fibonacci series up to user entered terms.
Code:
n=int(input("Enter how many terms you want to display"))
a=0
b=1
print(a, b, end=" ")
for i in range(3,n+1):
c=a+b
print(c, end=" ")
a=b
b=c

Output:
Enter how many terms you want to display10
0 1 1 2 3 5 8 13 21 34

6
Program 13: WAP in python to check whether a user entered number is prime number or not.
Code:
n=int(input("Enter a number"))
status=False
for i in range(2,n//2+1):
if n%i==0:
status=True
break
if status==True:
print("not prime")
else:
print("prime")

Output:
Enter a number9
Entered number 9 is not prime

Enter a number11
Entered number 11 is prime

Program 14: WAP in python to display prime numbers between the given number of ranges.
Code:
sn=int(input("Enter Starting number of range="))
ln=int(input("Enter last number of range="))
for n in range(sn,ln+1):
for i in range(2,n//2+1):
if n%i==0:
break
else:
if n==1:
pass
else:
print(n)

Output:
Enter Starting number of range=1
Enter last number of range=10
2
3
5
7

7
Program 15: WAP in python to display the reverse of a user entered integer number.
Code:
n=int(input("Enter a number"))
no=n
s=0
while n>0:
r=n%10
s=s*10+r
n=n//10
print("The reverse of a number",no,"is", s)

Output:
Enter a number845
The reverse of a number 845 is 548

Program 16: WAP in python to check whether a user entered number is a palindrome number or not.
Code:
n=int(input("Enter a number"))
no=n
s=0
while n>0:
r=n%10
s=s*10+r
n=n//10
if no==s:
print("This is a Palindrome Number")
else:
print("This is not a Palindrome Number")

Output:
Enter a number789
This is not a Palindrome Number

Enter a number787
This is a Palindrome Number

Program 17: WAP in python to check whether user entered number is an armstrong number or not.
Code:
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")

8
Output:
Enter a number: 121
121 is not an Armstrong number

Enter a number: 153


153 is an Armstrong number

Program 18: WAP in python to computer GCD (greatest common divisor) of two numbers.
Code:
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))

if a > b:
smaller = b
else:
smaller = a
for i in range(1, smaller+1):
if((a % i == 0) and (b % i == 0)):
gcd = i

print("GCD of numbers ", a, " and " , b, "is ", gcd)

Output:
Enter first number:125
Enter second number:50
GCD of numbers 125 and 50 is 25

Program 19: WAP in python to print the following pattern:


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

Code:
for i in range(1,6):
for j in range(1,i+1):
print("*", end=" ")
print()

Program 20: WAP in python to print the following pattern:


1
12
123
1234
12345

9
Code:
for i in range(6):
print()
for j in range(1,i+1):
print(j,end=" ")

Program 21: WAP in python to print the following pattern:


54321
4321
321
21
1

Code:
for i in range(5):
print()
for j in range(5-i,0,-1):
print(j,end=" ")

Program 22: WAP in python to print the following pattern:


A
AB
ABC
ABCD
ABCDE

Code:
for i in range(6):
print()
for j in range(65,65+i):
print(chr(j),end=" ")

Program 23: WAP in python to print the sum of the following series:
1+2+3+4+5+6…………………………………
Code:
s=0
n=int(input("Enter number of terms upto which you want to calculate sum="))
for i in range(1,n+1):
s=s+i
print("The sum of the given series upto",n,"terms=",s)

Output:
Enter number of terms upto which you want to calculate sum=5
The sum of the given series upto 5 terms= 15

10
Program 24: WAP in python to print the sum of the following series:
1+(1/2)+(1/3)+(1/4)+(1/5)+(1/6)…………………………………
Code:
s=0
n=int(input("Enter number of terms upto which you want to calculate sum="))
for i in range(1,n+1):
s=s+(1/i)
print("The sum of the given series upto",n,"terms=",s)

Output:
Enter number of terms upto which you want to calculate sum=5
The sum of the given series upto 5 terms= 2.283333333333333

Program 25: WAP in python to print the sum of the following series:
1+(1/!2)+(1/!3)+(1/!4)+(1/!5)+(1/!6)……………………………
Code:
def fact(x):
f=1
for k in range(1,x+1):
f=f*k
return f

s=0
n=int(input("Enter number of terms upto which you want to calculate sum="))
for i in range(1,n+1):
s=s+(1/fact(i))
print("The sum of the given series upto",n,"terms=",s)

Output:

Enter number of terms upto which you want to calculate sum=3


The sum of the given series upto 3 terms= 1.6666666666666667

Program 26: WAP in python to input a string from user and traverse it.
Code:
s=input("Enter a string=")
L=len(s)
for i in range(L):
print(s[i])

Output:
Enter a string=welcome
w
e
l
c
o
m
e

11
Program 27: WAP in python to input a paragraph from user and count the number of characters in it.
Code:
s=input("Enter a string=")
count=0
for i in s:
count+=1
print("The number of characters in the paragraph=",count)

Output:
Enter a string=Hello my name is xyz.
The number of characters in the paragraph= 21

Program 28: WAP in python to input a paragraph from user and count the number of uppercase
characters in it.
Code:
s=input("Enter a string=")
count=0
for i in s:
if ord(i)>=65 and ord(i)<=90:
count+=1
print("The number of uppercase characters in the paragraph=",count)

Output:
Enter a string=Hello my name is XYZ.
The number of uppercase characters in the paragraph= 4

Program 29: WAP in python to input a paragraph from user and count the number of vowels present in
it.
Code:
s=input("Enter a string=")
count=0
for i in s:
if i in "aeiouAEIOU":
count+=1
print("The number of vowels in the paragraph=",count)

Output:
Enter a string=Hello Where are you going?
The number of vowels in the paragraph= 10

Program 30: WAP in python to input a paragraph from user and count the number of words in it.
Code:
s=input("Enter a string=")
count=0
ss=s.split()
for i in ss:
count+=1
print("The number of words in the paragraph=",count)

12
Output:
Enter a string=Hello my name is XYZ.
The number of words in the paragraph= 5

Program 31: WAP in python to input a paragraph from user and count the number of “He” words in it.
Code:
s=input("Enter a string=")
count=0
ss=s.split()
for i in ss:
if i=="He":
count+=1
print("The number of He word in the paragraph=",count)

Output:
Enter a string=He is Mohan. He is a good Student. He always helps others.
The number of He word in the paragraph= 3

Program 32: WAP in python to input a string from user and check whether entered string is palindrome
or not.
Code:
s=input("Enter a string=")
s1=s[::-1]
print("Original String =",s)
print("Reversed String =",s1)
if s==s1:
print("String is palindrome")
else:
print("String is not palindrome")

Output:
Enter a string=nitin
Original String = nitin
Reversed String = nitin
String is palindrome

Program 33: WAP in python to input a list of numbers and display the largest value from it.
Code:
l=eval(input("Enter a list of integer elements="))
size=len(l)
largest=0
for i in range(0,size):
if l[i]>largest:
largest=l[i]
print("The largest among all list elements=",largest)

Output:
Enter a list of integer elements=[50,1,70,-9,100,45,30]
The largest among all list elements= 100

13
Program 34: WAP in python to input a list of numbers and display the second largest value from it.
Code:
import sys
l=eval(input("Enter a list of integer elements="))
size=len(l)
largest=slargest=-sys.maxsize-1
for i in range(0,size):
if l[i]>largest:
slargest=largest
largest=l[i]
elif l[i]>slargest:
slargest=l[i]
print("The second largest number among all list elements=",slargest)

Output:
Enter a list of integer elements=[70,-50,90,40,80,40,110,75]
The second largest number among all list elements= 90

Program 35: WAP in python to input a list of numbers and display the position of user entered number.
Code:
L=eval(input("Enter a list of integer elements="))
svalue=eval(input("Enter a searched element="))
size=len(L)
found=0
for i in range(0,size):
if L[i]==svalue:
found=1
break
if found==1:
print("The searched element",svalue,"is found at", i+1,"position.")
else:
print("The searched element",svalue,"is not found")

Output:
Enter a list of integer elements=[10,60,3,70,90,52]
Enter a searched element=90
The searched element 90 is found at 5 position.

Enter a list of integer elements=[10,60,3,70,90,52]


Enter a searched element=4
The searched element 4 is not found

14
Program 36: WAP in python to input a list of numbers and display the sum & average of list elements.
Code:
l=eval(input("Enter a list of integer elements="))
size=len(l)
sum=0
for i in range(0,size):
sum=sum+l[i]
print("The sum of all list elements=",sum)
print("The average of all list elements=",sum/size)

Output:
Enter a list of integer elements=[10,20,30,40,50]
The sum of all list elements= 150
The average of all list elements= 30.0

Program 37: WAP in python to input a list of numbers and display the sum of all odd values.
Code:
l=eval(input("Enter a list of integer elements="))
size=len(l)
sum=0
for i in range(0,size):
if l[i]%2!=0:
sum=sum+l[i]
print("The sum of all odd list elements=",sum)

Output:
Enter a list of integer elements=[15,80,33,40,72]
The sum of all odd list elements= 48

Program 38: WAP in python to input names of n students in a tuple and check whether a user entered
name is present in the tuple or not.
Code:
t=eval(input("Enter a tuples with student names="))
sstudent=input("Enter student name which you want to search")
size=len(t)
found=0
for i in range(0,size):
if t[i]==sstudent:
found=1
break
if found==1:
print("The student",sstudent, "is found in tuple at",i+1,"position.")
else:
print("This student is not found in this tuple.")

Output:
Enter a tuples with student names=("ram","shyam","monty","rahul","vickey")
Enter student name which you want to searchrahul
The student rahul is found in tuple at 4 position.

15
Program 39: WAP in python to input names of employees and their salaries, store them in a dictionary
and display this dictionary.
Code:
employee={}
n=int(input("Enter number of employee="))
for i in range(n):
ename=input("Enter employee name=")
esalary=int(input("Enter employee salary="))
employee[ename]=esalary

print("The employee details are:")


print(employee)

Output:
Enter number of employee=5
Enter employee name=rahul
Enter employee salary=5000
Enter employee name=keshav
Enter employee salary=4300
Enter employee name=mehul
Enter employee salary=9000
Enter employee name=ramesh
Enter employee salary=1500
Enter employee name=asif
Enter employee salary=6200
The employee details are:
{'rahul': 5000, 'keshav': 4300, 'mehul': 9000, 'ramesh': 1500, 'asif': 6200}

Program 40: Create a dictionary with the roll number, name and marks of n students in a class and
display the names of students who have marks above 75.
Code:
n=int(input("Enter number of students="))
sdict={}
for i in range(n):
srno=int(input("Enter student roll number="))
sname=input("Enter student name=")
smarks=int(input("Enter student marks="))
sdict[srno]=[sname,smarks]

print("The items of the dictionary=",sdict)


print("Names of those students whose marks are above 75:")
for k in sdict:
if sdict[k][1]>75:
print(sdict[k][0])

16
Output:
Enter number of students=3
Enter student roll number=1
Enter student name=Abhishek
Enter student marks=85
Enter student roll number=2
Enter student name=Rahul
Enter student marks=58
Enter student roll number=3
Enter student name=Parth
Enter student marks=95
The items of the dictionary= {1: ['Abhishek', 85], 2: ['Rahul', 58], 3: ['Parth', 95]}
Names of those students whose marks are above 75:
Abhishek
Parth

17

You might also like