0 ratings0% found this document useful (0 votes) 8 views32 pagesPython Programming Assignment
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Date
apt. No. Page No.__9
L=
o3.| Wako Pangan to define function with rutiple
[ween values vs
eS
| def cale (a, &):
r_| xen oth, a-b, axby asp
|_|
x ye 20, 10
odd, sub, mul, div = cale(%, y)
print ("Addition:” | add)
print [" Subbrctin :" , sub)
paint _(" Multiplication: rout)
paint (*Dinkien 2”, cbiv)
L_|
L_| =
L_|
r—
|
‘Teacher's Signature ————
aOutput '-
Addition ; 39
Subbaction ; 10
Mudfiplication 200
Division « 2-0Ds
fo itt ate = ~)
Bat PageNo. 9
or 1k
quo} Wik a python progtin to find >. fachvial of 0
{numbe?__using Recurs jon .
Hoel
l_| det foctoaial (n) +
| :
ea ons=0 or ne=ts
|_| scelusn 1
(a Ise:
zrelusn __h_x fachnral (n-1)
num = int (input ("enter a number: ))
paint C'fochral of" num, “is” , factorial (num)
OU.) Write a Acnipt tn point the current date in
nite a __ python
ty. Following fysmot - Wed 09 02:26:23 Ts 2020 //,
trem —-dotetine import __dadehime
now = dodetime. now ()
print (numshftime (na nd “~HtAM AS IST 2x")
f
‘Teacher's Signature —_————————Output :~
Enter a rumber: 5
foctwrial of 3 8 120.
Output t-
WeD 09 02526523 IsT 2020Date
Page No.__10
p,[wWrike a __Python progam to __convert emperctures to and
from Celtiud _ Fahrenheity [formulas Ye = t- %]
[ celsim = float (input (“Enker fempershure in celuius t “))
[Pohrenheit = ( Celsius % 9c) +32
[point (" Seis Celsius is equal to {fahrenheit} fahrenheit ")
fahrenheit = float (input (“enler emperahir jn fahrenheit :"))
Celsius = (fahrenheit ~ 39) x S%
print (£" fYabrnbat | falrerheit is equal tn feelin Coleius" }
E
134 2OQAAM. hn
for i. In va 2
foe jin range (2, i):
if ivpesd
beak
elses
print (i)
bacak
| ‘Teacher's Signature ________—a a I
Output; -
Gnter .. temp erature in. Celsius 0 \ i
bo celta fg equal to 32.0. fahrenheit,
En ter demper abate in fahrenheit s 212
ajo fahrenheit is equal to 10010 - Colt(usDate
Expt. No Page No.1 |
Loops and _ Conditionals
| Loop:
x
**
HN
x * *
{eh eee
for i In wange (1,5):
print _(” xi)
ais unite a __parogham to _phint__rulfpliation _tavbles of 8, 15,69
i “0
print (“M
for fin _yange (1) 18):
pzint (#" {etx {ih fexip")
print (Vn Mubtip ltcation “Table of iz”)
txt in ange C1.)
ms, paint (t" fis} Sit = fist }”)
point ("in Multileahion “Table of 692")
to {in vange (1,11) ¢
print Lt" {oo txtif = feaxi”)
Teacher's Signature —______————eK
HK
HHH
\
Mullipl cation Table of 8: — Multiplication “Table of IS: Mubbiplication Table of 69; !
Bx1 =8 sx leis 69xle 69
gx2=16 ISX2 = 30 69X2= 138
Sxz=2y ISx3= 4S CIXZ> 20
Bx4=9o ISX4= Co 69XYs OF |
8x3 = 4o 1sxs= FE 69xg2 Bde {
Bxe = 48 sexG= 90 69X6= YY
8xr= 56 ISXF= 10S 63xa= 483
Bxe= 64 ISxg = tro 69xg= 852
Sx9- 42 ISx9= (36 69X39. 621
RX1D= 8d textos [50
69xip = 690t. No.
Expt Page No.__12-
eg
| ale] Waite Program to check pohether the giver _thout _ ix
| digit i __[pweresge character ax uppercase
[| ; { chorackr or
a _Apecial character (tise if - eleeif | ladder),
=_input ("gniey a value: ”)
if S-ishumene() !
paint ("9 ts a number")
lelif _s-tslower) ¢
print (“9t ts 0 lowercase eller)
elit S-isupperO: ©
print (“$F 18 an uppercase fea”)
else:
paint ("9+ is a special charneka")
a3} prile a python —_pingham tp print the _fibonace} Sequence
using while Loop:
n= int (input ("énier how pray ferms you want :"))
Ob = 0,3
count = 0
hile Count Kh ¢
print (0, end="")
O,b = by ath
Count +=
‘Teacher's Signature —______ee
output
Enter a value t 34
gt ig a rumba-
Enkr a) values S$
Ot is a lowercase letter
Enter oa value: A
at is a uppercase (eter.
Enter a values@
gt ts a Apecial character
| Output :-
Enter how rrony terms you want : 6
Orr 23 5Date
Expt. No.
5 a
Shings. Page No.__{
a ==
[ott bivite A __prngnom to find the loth of __ the i
[_uiithowd _usirg any brary funefing.
shi = input (“enter a ch'ng +”)
length = 0 f
[| for char in chit
po th += 4
|__| print { 4" The_length of the string fst flergth}")
613.| Wake _prngrarn ty check if two shiings Okt __Ahos'raind
hot :
fri = Input (" énley the fired ching :")
thas input ("enter the teem — Shing”)
Shi = strt.|ower()
tea = shr2+ lower)
test =a
if len ( sht) == len(sh2)?
fox char tn st:
if char ~in cho:
pau
else:
tests
break
|_| else ;
test =o
el - ‘Teacher's Signaturebse
Enler the first ching ¢ Nilesh
Ente the Steod ating: Nikhil
Entered both Shing Nileth ard Nikhi
Eniex te fiset ching: Wi Listen
Enter the seed gtnrg, Silent
ntered — both ching Listen and
Silent
| rot
On A Ghaghamd
One Anagrams -Date
Expt. No. ——_________ Page No._44
fut:
print (f" Entered both Shring Sstr1l and {Sh2} an Ghavrmins") |
Lelse Li
point (4 Grlered both fnivg Lebrt | and {shr2} are thot anagram")
20! pote a ponghan to check if phe substring — is pried ent
lin. a—_given Abing os hot:
het = tnpub ( Gyla the main cfn'ng2")
ghe2 > Input (" fnley the Subs bring fh check")
check = +
jf sh2 in strit
Dass
F
else:
Check = 0
if check t
print (£" Tie Substring ‘Esha is _pretent tn the Inain
Abring “Eshett'”.)
elses
print (" The substring “tshe2}’ 1s not present tn the
main Atrirg ' Ssh)
‘Teacher's Signatureoutput: ~
Enler the main ftrhy Government
Enis te substring to checks Govern
Tre cubching “overn' fs present in
Quip
Eeihes the tal shirng ¢ Listen
subshing 48 check + Life
Enkr the
Tre subthing Life™ is not praent tr the main airing
CLishen®
the
Pron
Abang ”
vy :
Government!- — \ Seaman
Expt. No. SS
L— Lists Page No._1S
| bivike a .
alike ag ett! tegen stint
| 2 eG tp it) Insert Telia
lieing
at add
[sth = Ct, 2,3, 4 6]
list 1 append (¢)
print Costs )
# ingest
Lists. insert (6, 0)
print (uct 1)
ae slicing
print _( ustt (2:53)
i Ust#[ 241)
print ( ustt [9:)
print Cust [-22))
_print Custs [ :-27)
Teacher's Signature.Output + -
(1,293,9, 596) «add
C8 1,2, 3,9,5,6) e— insert
| C2,3,9) :
Co, 2,2, 3)
C3,4,8,6]
Cvsre)
Co, 1, 2,3) bear ‘|_| by taking “any ise 7
listt = C3, 9,8, 4,57
Usti-
[bist t+ insert ( 0,0)
| print Custs)
Lists. Bemove( 2)
print (list)
Lstt-Sort L)
paint Cuist+)
Lists. ev erse ()
print (bs#1)
623.)
ist of even hw.
piven List of hw
list = Ci, 2, 3, 4,556, 4,8, 9, 1b T
even—st = CI
for num ih __bi'st 2
if numnr
evenalisteappend( num)
print (“The even —rumben —In the dist net” cum lict )
‘Teacher's SignatureDubputs ~
tists = (3,2 87 5
> append
wt! 20312 3/6)
> Snsest
gt = U8 3 278 5/0)
+ Sort Remove
usps = C01 88, 1, 5,¢]
> Sort
usts = £0, 3/95/44
we Reverse
str = [8/6,9,/4,3, 0)
Output? -
C1, 2, 87 87h, 4 Be
110)
he even numbers in the st ones
ie eeExpt
=
[oss
Date
t. No. Page No. _1#
Write a pinghain to implement Around _hobin-
Ustt = (2,4, & J
Uist 2 = C1,3,5]
wesult = CJ
for i fn ange ( mrax(len(urts) len (Ust2))) ¢
if (< len(usts):
result append (usti CiJ)
ff < leh (ust):
gull append ( ste Ci)
[print ( result)
Tiples
ans)
Wile a program to creak tuple (rame, age, addseu, |
oolleye) fe atest two members and concotenske — the
tupls and print the toneatnakd tuplyy
Student l = (ghilesh" , 20, “122 Main Road" 5 “BEV untventily ")
shdent $= ("Balam , 01," 456 im cb” , “Hees allege")
Concakhated. tuple = Shdentl + strident 2
print (* The concotenakd tyole fi‘) Cone alen ated tup le)
‘Teacher's SignatureTrt 4, By 65984
The — concalenaled le tes
re
Cwiteth” , 20, 122 Main Road’ , (BED Univesity’, “Batram’ ,
215 tye elmst? » “aecs College’)Date
Page No. _!6
Wri a __prvaram tp rch the top (n? _ meat frequen Hy |
pocloning thors and thir resperhive __Couhk.
| eqs gaara bbbbecec, 2 should xehan Clas) (b, 9)]
tring = input ("énker a sings")
n= int (Input (“enky the value af ni")
chor count = {4
fey char in ching +
if chos th char_count :
char count [char] +21
else:
Chas count [char] = 4.
ayried chow = sorted Cohor_pount, ifemil))
for _i__in_ange Cimin (ns len (corte chass)))¢ |
print C4" ( fsorkdchasCiI [I | Cgorked iCu91)" pend ="
‘Teacher's SignatureDutpuls~
Enler a Stony:
Enter the "t.
(as) (b 4) Cc 3)
aaaaa bbbbcecd dad
of ns 3Expt. No.
{brik a progam ty count ty hurnber of vowels in
Date
PageNo._{3
ets
Abin
sh = inp (“Enter 4 ina :)
, t
vowels = ‘aeiou Aerou’
count = 0
fox__char in dy:
if chat th _voweh:
Count +=1
print (“Number of Vaselt:” . coun)
a8)
Lrife_o_prragham that displays which Lottew _patsent tn bath
Abiys !
SL= dapat Center fast string 2”)
sa = thet ("énler econ _ghring 2")
common = set (st)s intersection ( Set(s2))
Print (“ Common leHeg:” s Commen)
Teacher's SignatureButput ¢ — x
ender a ching + Aknosleg ment
Number of © Vowel t 4
Output : -
Enkr first ching: Shivam — Kurmak
Enkr — second eg t Nilesh Kumar
Common leHers: Fu? 457, 7, 47, Im, eI, QhgE
Date
ppt No. Page No._98
| Flom srognain _-tn 4 Uist of Ari the order
9. o__prsg Aort given Uist 0 i tn ox
[ot thule veel enande ‘ *
‘to
[ete =f "Mitesh", “Roushan", “shiva”, "Alok", Wiraj” . “Abhichek® ]
| jigt-vewel = CI
[ty ctr inst
count =0
| fux__ch in stot
Hooch in "pero aefou”
‘ Count +21
Ustvowel- append (count)
Lia2= Ust (zip (udvonel, st)
print (curled (ust2))
‘Dic Honawies
830] Wile a __gorogaam a ‘ctio ind
number _(hetueen f and n) in ‘fe __ form of (x, x*X)
he bi Ling ("Enis rumba :"))
for tt nat)?
i ange is teil
paint (square chet)
Teacher's Signature,Output: -
Ela
Welech') , £3rLRanshem bs (3 (shivam')-, (@, ‘Alok , (2, ning)
lesh') y ,
(B ‘Abhishet’) 5 (3, "Raushen') J
Output 5 -
Enky a numbers &
fries
faeug
facst
S410}
{s:as}
forse}
{:4a}
fereygExpt. No.
ete
Page No.__ 24
gs.[Wrike a _prvesam ty ohpoke ‘
edi Cy if a fiea—key exists th
[att =f lesa
‘bit2y
tong
i
key = Inpit ("Sry the key to cheele 2”
if indict: ¢ =
* a ¢ ’ .
ae print (f" the key tkeyt' is pocient in the dit hana”)
| ¢
a at bs , .
print (F" te key fkey} Ts not __poegent in fhe dickionayy)
2} Hie _a__prognar to add hen key ~ i
existing dicttonary - g vale Patt he
dictt = {qt
‘o t04
Sets
3 stn
det (1a) = 4+
—_| print je tion dicts
‘Teacher's Signature.7S
Output ¢ -
Enter the key te check : 6
“The key bic praca in th dictionary
Enkr the key te cheek + e o
The key fe “is hot present in the alietionary.
Output; -
Updating: Eolas, Wie sts sahe _ - _ _ _
Date
gxpt. No. Page No. 2 |
=
[pss] nie i a
[jackin
[dicts = ff sy
"7 at 22,
| Sls z
jee
[Holl = Sum ( clint. values(3)
print C“ The sum of _all_items in the dictionary iz" , tofel) |
Files
054.| Wrike a progam ty fort _Words_in_ file and put — them
tn anothin 9 fle. The tudput file thould rave only lower
case word , 1a ary uppidonse words thom _folrce |
rst be Inuered.
llth open (tinpubetxt™, @e™) at _infile:
wopd-=_infle _xead()+ (ower » Aplit()
swords .cortU),
With gpen C* Another txt" rtwt) as pubfile +
tubfle write (" _foin( worak))
print ("soled words have been unten 4 another text Fite”)
Teacher's Signature—————_—_—— ea
Output -
oh 6.
SENN git tems the dictionary é
thpubebet
My name is Nilesh Kumoa ard I gm cursently pursuung bteeh
th GEC Samastipur-
Console Odput ;
Sorted words have beer writer to anotha text file.
another-txt
am and — betech cussen ty ith te Kumar mg
name —nilesh pursiung Samastipur-—
03S:
word tn ate )
-—
=
t (ned teen text tile
with gpen ( "inp ube tet" ") ob file:
wordt = file xead()» lower). split ()
word — Count = ff
for__ ord in paordld
word count [word] = word — [Link] d,o)+t.
mnast. frequent. word = max (word chunt keye 1s0rd.- count get)
punt(#" The most
Frequently occuring voord is “f mail feguen! srl |
: ¢ "
with a count otf word-count Limo uent_ word 14”
L_|
aa
Teacher's Signature
KlEC
a3
Output t -
: [Link]:
Python Is a programming larguages Pyth on ts cay
python maka you & bell 4
leat: Learning
programinch «
Console Output >*
The — most frequently Scene word ue ‘py then
with a aount of 3.