Cs Practical File
Cs Practical File
x="welcome"
print (x, y)
OUTPUT:-
..... -. ...
"' -..
Python 3.8.3 (t.tg1/,J.8.3:6!llc832, lily 13 2020, 22:31:02) (MSC v.1124 64 bit (All
)64)) OD ruJ2
?ypt "btlp", •copyright", 'crtd!tl" or •u.,..,. () • for aoro illfonutioo.
»>
- - - - - - lttfflllT: C:/Pythooll/dcb.py - - - - - -
tnttr IliM:Anili ihltticbuy1
iMlccal!: Anika Bhattichuya
»> I
Q2) WRITE A PYTHON PROGRAM TO INPUT TWO NUMBERS AND DISPLAY THE
LARGER/SMALLER NUMBER.
CODE:-
if X>y:
else:
CODE:-
l=list ()
for i in range(y):
l.append(x)
print(I)
I.sort()
OUTPUT:-
... ,.. ,... ______
:CJ :l;~fn ~-=i.~ Jtag:s/vJ.o.J:6t8e8J2, May 13 2020, 22:37:02) [MSC
0 3
~-:- Type "help", .. copy1.·ight.", •credi ts 00 or "license<) .. tor 11\ore ir
< >>>
RESTART: C:/Pyt.honl8/q3.py - - - - -
enter the number ?
Qntg,r numOOr:23
enter number: 45
enter number: 6?
enter nur!'.ber: 94
on tor numbor: 12
ontor nurnbor: 68
enter nmr.bor: 90
(23, 45, 67, 9!1, l2, 68, 901
l.;ir:qost nurnbor: 94
~ma11ont nu111.bor: l2
»>
string="#"
pattern=''
pattern+=string
print(pattern)
OUTPUT:-
»>
------------------------- RESTART: C:/Python
t
u
m
HH
HfH
»> I
QS) WRITE A PROGRAM TO INPUT THE VALUE OF X AND N AND PRINT THE
SUM OF THE FOLLOWING SERIES:
print (m)
OUTPUT:-
= = = = = = FlSTART: C:Jfytnonl8/qi.py = = = =
enter a nu:rlierl
enter the 1L1Xi~111 po~r4
1
3
9
27
81
111.0
:» I
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(l,b+l):
if i % 2 == 0:
c -= ((a**i)/math.factorial(i))
else:
c += ((a**i)/math.factorial(i))
print("The sum is", c)
OUTPUT;-
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
>>>
def palindroae(n):
te11p =- n
rev • 0
while n > 0:
dig • n ll 10
rev = rev • 18 + di&
n • n II 10
if te■p == rev:
prlnt(tomp, "The numbtr Is a pallndr..,.!")
else:
prlnt(tomp, "The number lsn"t a pal1ndroae!")
def anntrong(n):
count = 0
teap • n
while te■p > 0:
digit • temp ll 10
count ♦= digit ** 3
t•"'P //• 10
if n =-• count:
print(n, "is an Armstrong number")
else:
print(n, "is not an Armstrong number•)
def perfect(n):
count = 0
for i in range(l, n):
if n :I: i == 0:
count = count + i
if count == n:
print(n, "The number is a Perfect number!")
else:
print(n, "The number is not a Perfect number!")
if _name '_main_':
n = int(input("Enter number:"))
palindr011e(n)
armstrong(n)
perfect(n)
OUTPUT:-
CODE:-
ifx%i==O:
break
elif x==l:
elif x==O:
else:
OUTPUT:-
CODE:-
a=O
b=l
print(a)
print(b)
c=O
while c<=n-b:
c=a+b
print(c)
a=b
b=c
OUTPUT:-
- - - ru:,JJMI, <.,1r1c11u11Jo/yJ.py - - - - - - - - - -
enter any number: 6
enter limit: 6
0
1
2
3
5
>»
Q9) WRITE A PROGRAM TO COMPUTE THE GREATEST COMMON DIVISOR
AND LEAST COMMON MULTIPLE OF TWO INTEGERS.
if(a>b):
minl=a
else:
minl=b
while (1):
break
minl=minl+l
OUTPUT:-
>>>
CODE: -
x=str(input("Enter a string:"))
vowel=uppercase=lowercase=constant=O
l=len(x)
for i in x:
vowel+=l
if i.isupper():
uppercase+=l
OUTPUT:-
x;str(input("Enter .. string:"))
vowel;uppercase;lowercase;constant;O
lalen(x)
tcr i n x:
1f(i--'a' or i --'e' or i - ' i ' o~ i--'o' er i--'u'):
vowel+;l
if i. is upper():
uppercase+;l
print("numbcr of vowol", vowel)
print("numbet o( t:on~Ldnl",1-vowel)
print("numbor of upporc.lso",upporcase)
print("nwnlJeL o( lowtHt:dse",1-uppercase)
CODE:-
x.sort ()
print ("largest number:", max(x))
OUTPUT:-
===================== REST;
enter the list of number 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.
print(I)
OUTPUT:-
...Python
,.-~°""""" -
3.8.3 (tag:,/v3.8.3:6f8c832, May 13 2020, 22:JJ:02) (MSC v.1924 f
Type '"help", "copyright", •credit:,• or "licen!le C) • tor more in!or:natior.
>»
-------------------------- RESTART: C:/Python38/st:r .py ---------------·
Lbt ct number.5 [232,345,564,JS,43]
(345, 232, 35, 564, 43]
>» I
OUTPUT:-
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:-
result={}
if result [marks)[1)>75:
print ('students who scored above 75:', result[marks][OI)
OUTPUT:-
QlS) WAP TO REMOVE All ODD NUMBERS FROM THE GIVEN INDEX.
for i in I:
if (i%2! =O):
1.remove(i)
OUTPUT:-
====== B!START: C:/Python38/buiefr.py =====
enter list of numbers:[24,46,57,68,68,68,46,325,582]
list after removal of odd numbers is [24, 46, 68 1 68 1 68 1 46, 582]
>»
CODE:-
l.sort(reverse=True)
print(I)
print (I [1])
OUTPUT:-
Enter a 11st of numbers [ 34,546,34434,656,345,)
[34434, 656, 546, 345, 34)
656
>>>
Code:-
imoor numpy a, np
x=eval(input("Enter a list"))
arr=np.array(x)
arrl=np.cumsum(arr)
print(arrl)
Output:
x-eval(input("Enter a list"))
freq={ J
tnr item in x:
if(item in freq):
freq[item]+=l
else:
freq[item]-1
for key, value in freq.items():
print("%d : %d"%(key,value))
output;-
Enter a list [23,53,5467,6743,23,546,53,90,67,90]
23 : 2
SJ : 2
54 67 : 1
6743 : l
546: 1
90 : 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.
S a 0
for a in 1st:
if int(a)ll:10aa3:
s +• a
print {"Sum of numbers ending with 3 in the list",s)
Output:
Q20) WAP TO SHIFT THE NEGATIVE NUMBER TO LEFT AND THE POSITIVE
NUMBER TO RIGHT.
l•eval(input( •enter eleinnts of • lis't: "))
n■ len(l)
print("Oricinal list:"~l)
for i in rance(n-1):
for j in range(n-i-1):
if 1 I i J ,0:
1 I i J. 1 I i + 1J • 1 I i + 11, 1 I i J
Output:-
Q21) WAP TO SWAP THE CONTENT OF A LIST WITH NEXT VALUE DIVISIBLE BY
7.
Output:•
Enter a list[3,21,56,43,63,28)
[28, 43, 21, 56, 3, 63)
»>
Q22) WAP TO ACCEPT VALUES FROM USER AND CREATE A TUPLE.
t~tuple ()
n-int.(inp,1t("~:nt.<'r n11mb<"r nlr-n,.nt:; lo t>0. lillec1:"))
~vL i ... u rd.nge (n) :
a:ci.nput. ("1:-:nrC'r nntthf'r: ")
t•t+ (a,)
prlnt("cutpul l•")
print (tl
Output:-
CODE:-
print()
cnt_dict = diet()
for i in range(n):
cnt_dict[x] = y, z
print()
for i in cnt_dict:
print()
if re in cnt_dict:
else:
»>