Computer Science
Project File
e
ame - Avinash
Pandey
Class - XI (A)
oll Number - 5We
: [e
This is certify that" Avinash Pandey”
of class XI has successfully completed his
“Computer science practical Report file”.
During academic session 2023-2024 as
per the guidelines issued by CBSE.
Teacher’s Signature
signature
DATEProgram
Signature
Write a python program to input a welcome message and display Tt
Write a python program to input two numbers and display the larger
smaller number.
Write a python program to input three numbers and display the largest
smallest number.
Generate patterns using a nested loop.
Write a program to input the value of x and n and print the sum of the
following series:
Nes reees
2) x = x/2! + x73) x44! + x45! — x46!
Write a program to determine whether a number is a perfect number, an
Armstrong number or a palindrome.
Write a program to input a number and check if the number is a prime or
composite number.
Write a program to display the n terms of a Fibonacci series.
Write a python program to compute the greatest common divisor and
least common multiple of two integers.
Write a program to count and display the number of vowels, consonants,
uppercase, lowercase characters in the string
Find the largest/smallest number in a list/tuple.
Input a list of numbers and swap elements at the even location with the
elements at the odd location.
Input a list/tuple of elements, search for a given element in the
list/tuple.
Create a dictionary with the roll number, name and marks of n students
in a class and display the names of students who have scored marks
above 75.
WAP to remove all odd numbers from the given
Index list.
WAP to display second largest element of a given
list.
WAP to display cumulative sum of elements of a given list.
WAP to frequencies of all the elements of
a list using a dictionary.
WAP in Python to find and display the sum of all the values which are
ending with 3 from a list.
WAP to shift the negative number to left and the positive numbers to
| right.Q1) WRITE A PYTHON PROGRAM TO INPUT A WELCOME MESSAGE AND
DISPLAY IT.
CODE: -
y=str (input ("enter name:"))
x="welcome"
print (x, y)
ouTPU
eS SS
Python 3.8.3 (tags/v3.8.3:6f8832, May 13 2020, 22:; (MSC ¥.1924 64 bit (AH
264) on in
‘Type "help", copyright", *credits" or "license()" for more information.
>
emcees ATA: C:/ython/ch.ry
foter name daikaRbttacharye
delcone Mita Bsttacarya,
»|
Q2) WRITE A PYTHON PROGRAM TO INPUT TWO NUMBERS AND DISPLAY THE
LARGER/SMALLER NUMBER.
CODE: -
xzint (input ("enter first number:"))
yzint (input ("enter second number:"))
if x>y:
print (x, "is greater than “, y)
else:
print (y, "is greater than ", x)fEython 3.9.3 (tags/v3.0.5:6f0e032, Hay 19 2020, 22:37:02) (HSC Vv.
Type "help", "copyright*, "credits" or *license()" for more infort
RESTART: C:/Python38/PRACTICAL XIC R.py
enter first mumber:10
enter second number :100
100 is qreater than 10
> |
Q3) WRITE A PYTHON PROGRAM TO INPUT THREE NUMBERS AND DISPLAY
THE LARGEST/SMALLEST NUMBER.
CODE: -
yzint (input ("enter the number "))
Islist ()
for i in range(y):
int (input (“enter number:"))
Lappend(x)
print(|)
Lsort ()
print ("largest number:”, max(I))
print ("smallest number:”, min(|))
OUTPUT: -Wohoe F090 : Way 9 2020, FaeFTTCRY AR
Q4) GENERATE PATTERNS USING A NESTED LOOP.
CODE: -
string="#"
pattern=""
for iin range (5):
pattern+=string
print(pattern)
QUTPUT: -
Q5) WRITE A PROGRAM TO INPUT THE VALUE OF X AND N AND PRINT THE
SUM OF THE FOLLOWING SERIES:
2) 14a ar. x
cop!
x=int (input ("enter a number:"))
n=int (input ("enter the maximum power:"))
As=0
for i in range (0, n+1):
s=x**)
print(s)
m=(x**(n#1)-1)/(1)
print (m)
(ii) x-x2/2! + x3/3! - x4/4! + x5/5!-x4/6!
CODE: -
import math
a = int(input("Enter value of a of series:"))
b = int(input(“Enter value of b of series:"))
c=0
for i in range(1,b+1):
if i% 2 =
c -= ((a**i)/math. factorial(i))
else:
¢ += ((a**i)/math. factorial (i))
print("The sum is”, c)Shell
Python 3.7.9 (bundled)
>>> %Run python. py
Enter value of a of series:4
Enter value of b of series:5
The sum is 4,.533333333333333
>>>
Q6) WRITE A PROGRAM TO DETERMINE WHETHER A NUMBER IS THE
PERFECT NUMBER, AN ARMSTRONG NUMBER OR PALINDROME.
CODE: -
def palindrome(n):
teep =n
rev = 0
while n > 0
dig eX 10
rev = rev * 10+ alg
aan s/f ie
if temp 22 rev:
print(tenp, “The nunber is a palindrome!"
else:
print(temp, “The number isn't a palindrome!)
def arastrong(n):
count = @
temp = 0
while teap > 0:
digit = temp % 10
count #= digit * 3
temp //= 10
if n == count:
print(n, “1s an Arestrong nusber")
else
print(n, "is not an Armstrong number")def perfect(n):
count = @
for i in range(1, n):
ifn ki
count = count +i
4 count
print(n, "The nunber is a Perfect number!")
else:
print(n, “The nunber is not a Perfect nunber!")
if _nane_ == '_pain_':
n= int(input("Enter number")
palindrone(n)
arnstrong(n)
perfect(n)
>>> %Run python. py
Enter number:1221
1221 The number is a palindrome!
1221 is not an Armstrong number
1221 The number is not a Perfect number!
>>> %Run python. py
Enter number: 496
496 The number isn't a palindrome!
496 is not an Armstrong number
496 The number is a Perfect number!
Q7) WRITE A PROGRAM TO INPUT A NUMBER AND CHECK IF THE NUMBER IS
A PRIME NUMBER OR COMPOSITE NUMBER.
CODE: -
xsint (input ("enter any number:"))for i in range (2, x):
if x%it
print ("it is a composite number")
break
elif x==1:
print ("‘t is neither prime number nor a composite number")
elif x:
print (“it is neither prime number nor a composite number")
else:
print ("itis a prime number")
OUTPUT: -
enter any nunber4
it is a composite number
>>>
enter any nunber2
it is a prime number
>>>
enter any nunber:56
it is a composite number
>>>
Q8) WRITE A PROGRAM TO DISPLAY THE N TERMS OF A FIBONACCI SERIES.
CODE: -
xcint (input (“enter any number:”))n=int (input (“enter limit:"))
a=0
b=1
print(a)
print(b)
c=0
while c<=n-b:
ceatb
print(c)
a=b
b=c
OUTPUT: -
Q3) WRITE A PROGRAM TO COMPUTE THE GREATEST COMMON DIVISOR
AND LEAST COMMON MULTIPLE OF TWO INTEGERS.
CODE: -
aint (input (“enter 1st number:"))
b=int (input (“enter 2nd number:"))import math
print ("the ged is:", math.ged (a, b))
iffa>b):
mint=a
else:
mint=b
while (1):
print ("the lem is:”, min)
break
mini=mini+1
OUTPUT:
>>
enter Ist number
enter 2nd number:
the ged is: 1
the lem is: 20
>>>
enter lst number
enter 2nd number:
the ged is: 1
the lem is: 56
>> |
Q10) WRITE A PROGRAM TO COUNT AND DISPLAY THE NUMBER OF VOWELS,
CONSONANTS, UPPERCASE, LOWERCASE CHARACTERS IN THE STRING.
CODE: -
xestr(input("Enter a string:"))
vowel=uppercase=lowercase=constant=0tsten(x)
for iin x:
vowel+=1
if isupper():
uppercaset+=1
print ("number of vowels”, vowel)
print ("number of constant", 1-vowel)
print ("number of uppercase”, uppercase)
print ("number of lowercase",1-uppercase)
QUTPUT: -
xeste(ingul ("Enter a sising:")
vowel=uppercase=lowarcase=constant=0
detent)
for f in x
iti iestit or dsetot cr isetuty:
vowel.
if ivisupper ():
print ("number of vowel", vowel)
print ("number of constant", 1-vowel)
print ("number of uppercase", upporcase)
print ("number of lowercase", 1-uppercase)
Q11) FIND THE LARGEST/SMALLEST NUMBER IN A LIST/TUPLE.
CODE: -
xeval (input ("enter the list of number to be computed:"))
xsort ()print (“largest number:”, max(x))
print ("smallest number:”, min(x))
ae a a = REST,
enter the list of nunber to be computed: (214,354, 346,56]
largest number: 354
smallest number: 56
>»
Q12) INPUT A LIST OF NUMBERS AND SWAP ELEMENTS AT THE EVEN
LOCATION WITH THE ELEMENTS AT THE ODD LOCATION.
CODE: -
Iseval (input ("list of numbers:"))
for iin range (0, len(l)-2,2):
i+), WD=Mi, Hid]
print(!)
OUTPUT: -
Q13) INPUT A LIST/TUPLE OF ELEMENTS, SEARCH FOR A GIVEN ELEMENT IN
THE LIST/TUPLE.CODE:
x=eval (input (“Enter 4
y-oval {input ("Enter elozent to bo found in the Tist*))
Ty ine
print (*y {a in the positions Reindaxty],tin tne rar
elset
print (‘elenent not found")
QUTPUT:-
¢RCR32, May 13 2020, 22737702) (4
2 Sereaiesr oF “1icensa()" tor more
ABSTART: C:/Python38/assignment -py ==
Q14) CREATE A DICTIONARY WITH THE ROLL NUMBER, NAME AND MARKS OF
N STUDENTS IN A CLASS AND DISPLAY THE NAMES OF STUDENTS WHO HAVE
SCORED MARKS ABOVE 75.
CODE: -
xzint (input ("enter the total no. of students:"))
result= {}
for iin range (x):
roll number=int (input (“enter roll number:"))
name=str (input (“enter the name:"))
marks=int (input ("enter marks:"))
result{roll number]= [name, marks]
for marks in result:
if result [marks][1]>75:print (‘students who scored above 75:’, result[marks][0])
OUTPUT:
_———__L_—_ZZ
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02)
D64)] on win32
Type "help", "copyright", "credits" or "license()" for mo
>>>
RESTART: C:\Python38\jhd5£3hk5-py
enter the total no. of students:3
enter roll number:25
enter the name:DISHA
enter marks: 36
enter roll number:34
enter the name: JANVI
re marks: 79
enter roll number:27
enter the name:ASHMITA
enter marks: 46
students who scored above 75: JANVI
>>>
Q15) WAP TO REMOVE ALL ODD NUMBERS FROM THE GIVEN INDEX.
CODE: -
Izeval (input ("enter list of numbers:"))
for iin |:
if (i%2! =0):
|Lremove(i)
print ("list after removal of odd numbers is",I)RESTART: C: /Python38/huiefr.py
enter list of numbers: [24,46,57,68,68,68 46,325,582]
list after renoval of odd numbers is (24, 46, 68, 68, 68, 46, 582]
»>
Q16) WAP TO DISPLAY SECOND LARGEST ELEMENT OF A GIVEN LIST.
CODE: =
Iseval {input ("enter list of numbers:"))
I sort(reverse=True)
print(I)
print (I (2)
OUTPUT: -
Enter a list of numbers [ 34,546,34434,656,345,]
(34434, 656, 546, 345, 34]
656
>>>
Q17) WAP TO DISPLAY CUMULATIVE SUM OF ELEMENTS OF A GIVEN LIST.
Code:-import numpy as np
x=eval (input ("Enter a list"))
arr=np.array (x)
arrl=np.cumsum(arr)
print (arrl)
Enter a list [23,5,54,57]
[ 23 28 82 139]
>>>
Q18) WAP TO FREQUENCIES ALL THE ELEMENTS OF A LIST USING A
DICTIONARY.
CODE: -
x-eval (input ("Enter a 1ist*))
freq=(}
tor item in x:
if (item in freq):
freq{item]+=1
else:
freq[item]=1
for key, value in freq.items():
print ("$d : %d"% (key, value) )Enter a list 123,53,5467,6743,23,546,53,90,67,901
23:2
53:2
5467:
6743:1
546:190:2
67:1
Q19) WAP IN PYTHON TO FIND AND DISPLAY THE SUM OF ALL THE
VALUES WHICH ARE ENDING WITH 3 FROM A LIST.
CODE:-
1st eval(input("Enter elements of a list: "))
58
for a in 1st:
if int(a)%10==3: s+ a print ("Sum of numbers ending with 3 in the list',s)
Output:
>>> %Run python.py
Enter elements of a list: [13,34,33,45,93]
Sum of numbers ending with 3 in the list 139
>>>
Q20) WAP TO SHIFT THE NEGATIVE NUMBER TO LEFT AND THE POSITIVE
NUMBER TO RIGHT.
CODE:-AvevalCinput(“Enter elements of # 1dst:*))
pelen(a)
print ("Original 1ist:",1)
for 4 An range(n-2
for 4 in range(n-i-1
watdie
LCG LACS+ Merges
print(wAfter shifting list is:", 1)
>>> %Run python. p
Enter elements of a List: (-23,54,43,-31,-1,211
Original list: (-23, 54, 43, “31, ~1, 21)
After shifting list is: (54, 43, 21,/-1, -31, -23)
>>>