Sophia Girls' Senior Secondary School Saharanpur Computer Science (083) Practical File For Class-Xi SESSION:-2020-2021

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

SOPHIA GIRLS’ SENIOR SECONDARY SCHOOL

SAHARANPUR

COMPUTER SCIENCE (083) PRACTICAL FILE


FOR CLASS-XI
SESSION:-2020-2021

SUBMITTED TO: SUBMITTED BY:


Mrs.RENUKA BHATEJA ANUSHKA CHAUHAN
PGT(Comp.Sc) CLASS:XI-C
CERTIFICATE
This is to certify that Anushka Chauhan student
of class XI-C has successfully completed the
computer science project of Python under the
guidance of our computer teacher
Mrs.Renuka Bhateja.

Yours truly
Anushka Chauhan

Teacher’s sign.
(Mrs.Renuka Bhateja)
PGT(Comp.Sc)
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to
our principal Sister.Lucy who gave me the golden
opportunity to do this wonderful project of computer
science(083) through which I came to know about so
many new things.

I would like to thank my computer teacher Mrs.Renuka


Bhateja,whose valuable guidance has been the ones that
helped me patch this project and make it full proof
success and her instructions has served as the major
contributor towards the completion of the project.

Then I would like to thank my parents who have helped


me a lot in finalizing this project within the limited time
frame.

Last but not the least I would like to thank my classmates


who have helped me a lot.

THANKS AGAIN TO ALL WHO HELPED ME

Anushka Chauhan
XI C
INDEX
(1) Cover page
(2) Certificate
(3) Acknowledgement
(4) Program to compute Simple and compound interest
(5) Program to find area of triangle
(6) Program to print the script
(7) Program to check the range
(8) Program to take integer n and print Fibonacci series
(9) Program to input 3 nos. and display the largest and smallest
number.
(10) Program to calculate x^n
(11) Program to display the terms of Fibonacci series
(12) Program to compute HCF and LCM of 2 integers
(13) Program to find largest/smallest no. in list/tuple
(14) Program to swap the elements.
(15) Program to input a list/tuple of elements,search for a given
list/tuple
(16) Program to create a dictionary
(17) Program to perform four tasks
(18) Program to check the password
(19) Program to print the sum of the series
(20) Program to determine whether a number perfect,
Armstrong or palindrome
(21) Program to input a string determine whether it is
Palindrome or not
(22) Program to count and display the number of vowels,
consonants,uppercase,lowercase characters in string.
(23) Program to input a list and test if it is equal to the sum of the
cubes of its digit and find smallest and largest number from list
CONCLUSION
Here, I have came to the end of the project of Computer
Science of Python of (083) code. It was a wonderful and
learning experience for me while working on this
project.This project took me through the various phases
of project development.I enjoyed each and every bit of
work I had put into this project.
BIBLIOGRAPHY
The content for this project report has been
taken from the following sources:
 www.google.com
 Taken source from a source book
“Computer Science With Python”
Written by Preeti Arora.
And taken help of our computer teacher
Mrs.Renuka Bhateja.
Program 1:Write a program to compute simple interest and
compound interest.
Solution input:
#Simple and Compound interest
#Reading principal amount,rate and time
principal=float(input('Enter amount:'))
time=float(input('Enter time:'))
rate=float(input('Enter rate:'))

#Calculation
simple_interest=(principal*time*rate)/100
compound_interest=principal*( (1+rate/100)**time-1)

#Displaying result
print('Simple interest is:%f'%(simple_interest))
print('Compound interest is:%f'%(compound_interest))

Program 1:Output

Enter amount:30
Enter time:5
Enter rate:20
Simple interest is:30.000000
Compound interest is:44.649600
Program 2:Write a program to find the area of a triangle using
formula ½*base*height.
Solution input:
#Python Program to find area of a triangle using base and
height

base=float(input('Enter the base of a triangle:'))


height=float(input('Enter the height of a triangle:'))

#calculate the area


area=(base*height)/2

print("The area of a triangle using",base,"and",height,"=",area)

Program 2:Output

Enter the base of a triangle:5


Enter the height of a triangle:10
The area of a triangle using 5.0 and 10.0 = 25.0
Program3:Write a script to print the following:
8
86
864
8642
Solution input:
for i in range(0,5):
for j in range(0,i):
print(8-2*j,end=' ')
print()

Program3:Output

8
86
864
8642
Program4:Write a program that checks in the range 1………100
and prints the “Fizz” if the number is multiple of 3 and prints
“Buzz” if the number is multiple of 5.It should print “Fizz Buzz” if
the number is multiple of both 3 and 5.
Solution input: for fizzbuzz in range(101):
if fizzbuzz%3==0 and fizzbuzz%5==0:
print("fizzbuzz")
continue
elif fizzbuzz %3==0:
print("fizz")
continue
elif fizzbuzz %5==0:
print("buzz")
continue
print(fizzbuzz)

Program4:Output

fizzbuzz
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
fizz
22
23
fizz
buzz
26
fizz
28
29
fizzbuzz
31
32
fizz
34
buzz
fizz
37
38
fizz
buzz
41
fizz
43
44
fizzbuzz
46
47
fizz
49
buzz
fizz
52
53
fizz
buzz
56
fizz
58
59
fizzbuzz
61
62
fizz
64
buzz
fizz
67
68
fizz
buzz
71
fizz
73
74
fizzbuzz
76
77
fizz
79
buzz
fizz
82
83
fizz
buzz
86
fizz
88
89
fizzbuzz
91
92
fizz
94
buzz
fizz
97
98
fizz
buzz
>>>
Program5:Take an integer input N from the user print N
Fibonacci numbers.Recall that fibanocci series progresses as 0 1
1 2 3 5 8……..
Solution input: #Python program to generate Fibonacci series
until 'n' value
n=int(input("Enter the value of 'n'"))
a=0
b=1
sum=0
count=1
print("Fibonacci Series:",end = " ")
while(count <=n):
print(sum,end= " ")
count += 1
a=b
b=sum
sum=a+b

Program5:Output

Enter the value of 'n'10


Fibonacci Series: 0 1 1 2 3 5 8 13 21 34
Program6:Input three numbers and display the largest/smallest
number.
Solution input: #Python program to find the largest/smallest
number
number1=int(input('enter first number:'))
number2=int(input('enter second number:'))
number3=int(input('enter third number:'))

def largest(num1,num2,num3):
if(num1 > num2)and(num1 > num3):
largest_num=num1
elif(num2 > num1)and(num2 > num3):
largest_num = num2
else:
largest_num = num3
print("The largest of the 3 numbers is:",largest_num)

def smallest(num1,num2,num3):
if(num1 < num2)and(num1 < num3):
smallest_num=num1
elif(num2 < num1)and(num2 < num3):
smallest_num = num2
else:
smallest_num = num3
print("The smallest of the 3 numbers is:",smallest_num)

largest(number1,number2,number3)
smallest(number1,number2,number3)
Program6:Output

enter first number:26


enter second number:14
enter third number:25
The largest of the 3 numbers is: 26
The smallest of the 3 numbers is: 14
Program7:Given two integers x and n,compute x^n.
Solution input:
#Python program to calculate x^n

def power(x,n):

if(n==0):return 1
elif(int(n%2)==0):
return(power(x,int(n/2))*
power(x,int(n/2)))
else:
return(x*power(x,int(n/2))*
power(x,int(n/2)))
x=2;n=3
print(power(x,n))

Program7:Output

8
Program8:Display the terms of a Fibonnaci series.
Solution input: #Python program to display the terms of a
fibonacci series.
a=int(input("Enter the terms:"))
f=0
s=1
if a<0:
print("The requested series is",f)
else:
print(f,s,end=" ")
for x in range(2,a):
next=f+s
print(next,end=" ")
f=s
s=next

Program8:Output

Enter the terms:6


011235
Program9:Compute the greatest common divisor and least
common multiple of two integers.
Solution input: #Python program to find HCF and LCM
def find_gcd(a,b):
gcd=1
for i in range(1,a+1):
if a%i==0 and b%i==0:
gcd=i
return gcd

first=int(input('Enter first number:'))


second=int(input('Enter second number:'))

print('HCF or gcd of %d and %d is %d'


%(first,second,find_gcd(first,second)))

lcm=first*second/find_gcd(first,second)
print('LCM of %d and %d is %d' %(first,second,lcm))

Program9:Output

Enter first number:15


Enter second number:18
HCF or gcd of 15 and 18 is 3
LCM of 15 and 18 is 90
Program10:Find the largest/smallest number in a list/tuple.
Solution input: #Python program to find Largest/smallest
number in a list/tuple
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))

Program10:Output

How many numbers:6


enter number25
enter number96
enter number32
enter number54
enter number74
enter number29
Maximum element in the list is : 96
Minimum element in the list is : 25
Program11:Input a list of numbers and swap elements at the
even location with the elements at the odd location.
Solution input: #Python program to input a list and swap the
elements at even location with the elements at odd location.
#Code to get list from user
L=[]
N=int(input("Enter the size of the list:"))
print("Enter the elements one by one:")
for i in range(N):
E=int(input("->"))
L.append(E)

print("The given list is:")


print(L)

#Code to swap the elements at even location with the elements


at odd location.
for i in range(1,N,2):
L[i],L[i-1]=L[i-1],L[i]

print("\nThe list after swaping is:")


print(L)
Program11:Output

Enter the size of the list:10


Enter the elements one by one:
->1
->2
->3
->4
->5
->6
->7
->8
->9
->10
The given list is:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

The list after swaping is:


[2, 1, 4, 3, 6, 5, 8, 7, 10, 9]
Program12:Input a list/tuple of elements,search for a given
element in the list/tuple.
Solution input: #Python code to find the tuples containing the
given element from a list of tuples.
#list of tuples
Input=[(14,3),(23,41),(33,62),(1,3),(3,3)]

#Find an element in list of tuples.


Output=[item for item in Input
if item [0]==3 or item [1]==3]

print(Output)

Program12:Output

[(14, 3), (1, 3), (3, 3)]


Program13: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.
Solution input: n=int(input("Enter n:"))
d={}
for i in range(n):
roll_no=int(input("enter roll no:"))
name=input("Enter name:")
marks=int(input("Enter marks:"))
d[roll_no]=[name,marks]
for k in d:
if(d[k][1]>75):
print(d[k][0])

Program13:Output
Enter n:3
enter roll no:1
Enter name:Aayushi
Enter marks:90
enter roll no:2
Enter name:Amisha
Enter marks:70
enter roll no:3
Enter name:Amyra
Enter marks:33
Aayushi
Program14:Write a python program that should perform the
following four tasks:
(i)After getting a word from the user ,your program should print
each letter of the word.
(ii)Your program should use another loop to print each letter of
the word in reverse.
(iii)Make a new variable that is the original word in reverse and
print that variable.You can use ‘string slice’.
(iv)Ask the user for a letter to count.Use another loop to count
how many times that letter appears in the original word.Print
this count.

Solution input: word=input('enter a word:')


l=len(word)
for i in word:
print(i)
print("loop in reverse:")

for i in word:
a=word.index(i)
print(word[l-a-1])
print()
reverse=word[::-1]
print(reverse,'is the original word in reverse')
print()

var=input('enter the letter for count:')


j=0
count=0
while j<l:
if word[j]==var:
count=count+1
j=j+1
print('The number of the letter present in the word are',count)

Program14:Output

enter a word:Python
P
y
t
h
o
n
loop in reverse:
n
o
h
t
y
P

nohtyP is the original word in reverse

enter the letter for count:P


The number of the letter present in the word are 1
Program15:Write a program that prompts a user for their
“password” and then determines if the password is valid or not.
A password is said to be valid if it starts with a digit and it has
length of 6 or more.Otherwise print password incorrect.

Solution input: #To check whether the password is valid or not


PW=input("Enter the password:")
l=len(PW)
for i in PW:
if i.isdigit():
if l>6:
print("Password correct")
else:
print("Password incorrect.There must be six characters")
else:
print("Password incorrect.Password must start with a
digit")
break

Program15:Output
Enter the password:kaushik30
Password incorrect.Password must start with a digit

Enter the password:30py


Password incorrect.There must be six characters
Enter the password:30kaushik
Password correct
Program16:Write a program to input the value of x and n and
print the sum of the following series:
x+x^2/2!-x^3/3!+x^4/4!+…………x^n/n!

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


n=int(input("Enter the value of n:"))
Sum=x
for i in range(2,n+1):
Fact=1
for j in range(i,1,-1):
Fact=Fact*j
NextTerm = (x**i)/Fact
if i%2==0:
Sum=Sum+NextTerm
else:
Sum=Sum-NextTerm
print("The sum of series is:",Sum)

Program16:Output

Enter the value of x:4


Enter the value of n:6
The sum of series is: 9.155555555555555
Program17:Determine whether a number ia a perfect
number,an armstrong number or a palindrome.

Solution input: #Python program to check if the number is


armstrong,perfect or palindrome
#take input from the user
num=int(input("Enter a number:"))
#initialize sum
sum=0
#find the sum of the cube of each digit
temp=num
while temp>0:
digit=temp%10
sum+=digit**3
temp//=10

#display the result


if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
sum1=0
for i in range(1,num):
if(num%i==0):
sum1=sum1+i
if(sum1 == num):
print("The number is a perfect number")
else:
print("The number is not a perfect number")
rev=0
temp = num
while(num>0):
dig=num%10
rev=rev*10+digit
num=num//10
if(temp==rev):
print("The number is a palindrome")
else:
print("The number is not a palindrome")

Program17:Output
Enter a number:407
407 is an Armstrong number
The number is not a perfect number
The number is not a palindrome
Program18:Input a string a determine whether it is a
palindrome or not;convert the case of characters in a string.

Solution input: #Function that will return reverse of a string


def isPalindrome(s):
return s == s[::-1]
#Driver code
str='RADAR'
ans = isPalindrome(str)
if ans:
print("Yes",str,"is palindrome")
else:
print("No,word",str,"is not palindrome")

#converting case of palindrome


if(str.islower()):
print("lower case is converted to UPPER case:",str.upper())
else:
print("UPPER case is converted to lower case:",str.lower())

Program18:Output

Yes RADAR is palindrome


UPPER case is converted to lower case: radar
Program19:Count and display the number of
vowels,consonants,uppercase,lowercase characters in string.

Solution input: str=input("Enter a string:")

vowels=0
consonant=0
lower=0
upper=0
for i in range(0,len(str)):
ch=str[i]
if((ch>='a' and ch<='z') or (ch>='A' and ch<='Z')):
ch=ch.lower()
if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'):
vowels+=1
else:
consonant+=1
for i in range(0,len(str)):
ch=str[i]
if(ch>="a" and ch<="z"):
lower=lower+1
elif(ch>="A" and ch<="Z"):
upper=upper+1
print("Vowels:",vowels)
print("Consonant:",consonant)
print("Lower Case Letters:",lower)
print("Upper Case Letters:",upper)
Program19:Output

Enter a string:Motivate
Vowels: 4
Consonant: 4
Lower Case Letters: 7
Upper Case Letters: 1
Program20:Input a list of numbers and test if a numbers is equal
to the sum of the cubes of its digits.Find the smallest and largest
such number from the given list of numbers.

Solution input: def cube_sum(n):


sumc=0
nstr=str(n)
for i in range(len(nstr),0,-1):
sumc=sumc+int(nstr[-i])**3

return sumc == n

num_list=[587,742,15,441,919,782,153,318,688,556,407]
pass_lst=[i for i in num_list if cube_sum(i)]
if pass_lst:
print("list of qualified numbers:",pass_lst)
print("Max:",max(pass_lst))
print("Min:",min(pass_lst))
else:
print("No number in the list is qualified")

Program20:Output

list of qualified numbers: [153, 407]


Max: 407
Min: 153

You might also like