0% found this document useful (0 votes)
2 views19 pages

Python Assignment 3 Ans

The document outlines various programming functions and algorithms related to computer science, including digit extraction, palindrome checking, vowel identification, and binary to decimal conversion. It also includes functions for calculating dates, generating Fibonacci sequences, and handling Roman numerals. The content appears to be instructional material for students in a computer science course.

Uploaded by

nikkirath2003
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)
2 views19 pages

Python Assignment 3 Ans

The document outlines various programming functions and algorithms related to computer science, including digit extraction, palindrome checking, vowel identification, and binary to decimal conversion. It also includes functions for calculating dates, generating Fibonacci sequences, and handling Roman numerals. The content appears to be instructional material for students in a computer science course.

Uploaded by

nikkirath2003
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/ 19

Department of Computer Science &Engineering

Faculty of Engineering &Technology (ITER)

MINOR- AsslGNMENT-3
FUNCTIoNS

4et kintep thee diget


-go eat et - digit s (num):
eat ast , seong-geitest,trd-gtete
O, 0,
it len (num) < 2 :
$rentet
elik len (num) < 3:
m(it(numto), int(num[17)
Ceeong-g Catet min(int (numLo) ), int(numla)) )

qreatest, Secony-27eatet, third_gneatet


num [oJ , numT1] , num[2)
for i in num:
it( int (i) > int (9?entet )):
hird -gseatet secon greget
qreatert

etsnL t e t seLOng greatet, taerdgrutot

input (F es a nun ber: )

(fid -97eatet- digit s(num))


trint
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)

2. de fiel-num s():

for i in TAe(1o0 , sot):


Ppend (i)

Pint (finol -nums(O)


3. - eNen)i

tot 0
fo n wm in Tnge(2, Sl, 2):
toty n m** 2

Itetrn totuy

ttesult > Sum- Squres -erent)


Print (re sut)

de rerer ce -tmng (ctmng:

for i in mnge (len(sering) -l, -l,-1):


seNeSe
Iietun

inp ut (Ent en ctoing: ")


ctring
Pind (t Rvess e ltmuy' }revene
Engineering
Department of Computer Science & (ITER)
Technology
Faculty of Engineering &

digit s (num ):
s. det hem ber of-
digt - (e unt er
0
while
Countes t 1
-

num =int (inplt ( Enter the num ber:


)
Print (number_o4- digets ( num))
|6 def ic -palinqome (tring):
i, j- o, len (s tring ) -1
Wkile i<j:
it coringti) !*
return Fase
ctringli:

ret un True

String input Enter a ttring:")


Prind (f"{st ving ? a Pali njonme :fis-palindrome(*tring)? ))
7. et is- vowel(Ch araeter):
rteturn Charat er in'aeiou AE1OU
inpt Ent er a Chartactes: )
if is _vowes (chartALt er ):
Print (ffcharrater is a vowel. ")
else:
Pri ntf charcaerer is a con sOnant. ")
Department of Computer Science &
Engineering
(ITER)
Faculty of Engineering & Technology

-month(mon+h ):
det days - in
m o n t h . l o w e r()
month =

days - di u
3)
january
febauany
30)

may1.31)
! 30)

"jesy":3i,
+:31
"september : 30,
"oto ben

" noyember : 30,

deeembes

ge (month, "Iovali'd month


reun cdays- o'ct hame)

mon th- n am e input Ent er month name : )


in-month(mondh -wne)
Prein (days
Department of Computer Science & Engineering
Faculty of Engineering &Technology (ITER)

9. det binay - to- deeimal (binwny):

linmy inaoy I: : -1]


for digit in binay:
deima t it (digit ) + 2 ** porwer

tetusn deim al
odet deema- to binmy (deima):
bin avg
if deimat =0:
rtetusn
while deuma >0!
binary > tr (deimal %2) t binwny
deuma Il2 2

binny
inpu("Eex a
1)
number: )
bìnay binmy
Prcint (f he deima equvalent ot binny f is
jbinny to- deuimn (aimy)) number: ))
deumay i t (input ("Ent eY a deimay
eguivlent ot fdeim? is
Print (f The binmy
Sdeeimej-to_ binaryldeima).")
Department of Comnputer Science & Engineering
Faculty of Engineering &Technology (ITER)

det wique- permut atioms(t mng-):


if len (ting-) <=1:
Pemutions set)

for i in hnge (ler (string-)):


string-[i3
nenainigchze »cering-iC :i3 +sering -
[it4 :]
wiue-pesmutntins (7emaining
for perm in
Chons ):
churtpem)
Permuttions. ald (curent

return permutations

Stving "abe
2 wnique- pexmutaIons (St ring-)
rtesult
A) wigue peim latationt of { t ing-? :)
Print (f
Tesuet:
tor perm in
Print (pe m)

form-palingome (st-):
det can-
list(Ch.lower () for Ch in str
‘ Cch.is a<num (0)
( e t 0 - Cha s 2 Se (ch. lower() fo h in st
if ch.i Sajnem l))
Court z0

Regd. Number:
Department of Computer Science & Engineering
Faculty of Engineering & Technology (ITER)

fore ch in iet_ of-Ch we:


it üst of - Chas. cownt (th) %2!> 0;

Ieturn Fase

rtet rcn Treue

det can-fom- plindome 2(st 7-):


Char- Cote
for ch in Ctr-:
it eh. isNnuml):
Ch ch.lowe ()
Chr_count es ch] char Conter.

tor e o t in Chr_ Corer. Vlueil):

if Count 2!z 0:

Geld Dnt er t= 4
retrn oed- Cot er (=

input ('Ent en a
Print (? {ier-?
Palinel ome : }cay- tom- palingjome (str- )?)
Print (f fsta-7 Can be arrnnyel Cat taean to
fon a palindaomei Can-fom- palindome2
(sta-)?")
Department of Computer Science && Engineering
Faculty of Engineering &Technology (ITER)

fon date time importt oatetimne, timedeta

days -of week " Mondny, Tueday, wednes dny


'hursdny 'iritay','canday',
(und ay' J

del
in put Ent en foday sde/YYYY -MM-DD
Mony):)
day str - hput ( Fntes todays day(eg-
:))
num -daye - Int (input'EnLes nmker of daysnum-4ay s
teturn date-str day- st o.capitalize (),
dat e-sty

num_days):
det caulate -neN date (date - st, day_st,
toy datetime. stoptime (date-I,
toay dat e

VaueE r :
except e
dute fomat. please
Prcint Lnvalid YYYY- MM -DP.)

retun
week'
no+ indays - ot-
day-Str
f
Print ("n valid day

timedelta (day[znum y
new date toay- date +
nd erldayst)
days~o wesk.
et -day ing er z
Regd. Number:
Department of Computer Science &Engineering
Faculty of Engineering &Technology (ITER)

tu ent-duy ind ex t nm-uy s) %


new day - inder=
= ot week (new- 4 ay in ex)
new dey deys-
fne-dae. strttime ( r-%,n
Print (f nNew date : %.4')")

(p'New day: fnew day? )


Print
Tdet main( ):
nys getuter-inplt
St,qay str) n um
d ate
Str, day Sto, nunays
Cayelatenew-dat e (date-
main -

Macn ()

13. det Toman to - int eger(oman ):


roman-vlues 2

I:1)

DS00,
Department of Computer Science & Engineering
(ITER)
Faculty of Engineering & Technology

tot al =0
Paev- value 0

char in reNerse (oman ):


fos
Curen_Vaue oman-Valueschar ]

CurntValue
<pTeN Value:
if vaue
ur ent
tot ay - -

elsei
entvaue
foty t= Cur

Cwr ert
val e
Porev yue

t e t urn total
e3a):").
Roman num
Erten a
input ( ('Ent
tom an -num 2 a
Stip() uppeo ()

of !
fcoman-nm

ntege equvadent
Prin (4 he
eger- Vaju )
int
14. num be (num ):
def is a m 4ong
um )
nm Sty z Clo(n
len(num - s t )
Pow er Power
fon

- Sum >Sum (it (digit)


armstoo o i g t in nwm_stY)
Department of Computer Science & Engineering
Faculty of Engineering &Technology (ITER)

numb er : ))
numb ex > int (input Etes a
(n umbn )!
iH is- asm Stoong - nwmb es nwnber.")

Print (f nembex is an Amltong


number.")
else
frit (f numbes fis not an

15. det nth- fibonalei (n ):

retn Ln put Shouw d be a posiHve


eik n 1!

Itetun 1

fist ,seohd > 0, 1


fos-in mmge (2, n): fist t selond
fist Seeond Seeo ng

Feun selond

Prin (nth- fi b0ha i(n))

det calculato C):

nem floa
float (in put ( 'Ent en the fiast
ncum b 23: ))
operao inpus ('Eng er an ope to (4-, *
-float (inpu ('E en the secoynm ber: )
num 2 zfloa
Engineering
Department of Computer Science & (ITER)
Technology
Faculty of Engineering &&

eliK opeT ato

elit opUto?
':
elit
-6efEtt nttttm2

2er0 is wndefneo.
2 0!
)f n n 2 z
D i v i n by
"E :
1num 2
ree ult > n m

wse t,-,t, 0
else:
opesto. pleaye
"Invalid

is : foesue ?
t

etn

ex cept Valuets
erter n wnen c
"Invali'd input. Please
TCetuyn
Vajues."

22
men

Callator ()
tutp lut

Pnent (o ut put )
Department of Computer Science & Engineering
Faculty of Engineering &Technology (ITER)

7. det emove. Voweis (text):


t
Vowels = aeiou AE1O

rt etusnI.jon (char cha in tet it


fo
Char not in Vowe/ s)
det mainl):
Usesinput input ('frt en a a

Point ( stig witteout vowelsfremlt?)


men
main ()

det isanag nm (stv1 , Sto2) .


cleanee-t11 .jotn (stv1 . lewe ?(). spit0)
Clean ea st 2 .jotn(ct 2 -lowes()- spit))
un Sorte (Cleane|- Sto1 )= 2 orteol(
CleaneslStY 2)
et main () :

S2 2 input ('Enten the sewn etmng :)


if is- anagrm ($1 , s2):
Print "The anagoms. ")
else:

Print (The Ctoings anag amy.")


1f- nne 22 Main:
main ()
Department of Computer
(ITER)
Faculty of Engineering &Technology

i9. e Pind- g C ( num 1 , num 2 )


min(numt Du
max mìn- ? mAx(nmi, num2),

ohile min ~ ! 0: mun


Min) ma
max- Min >

tetIn mo
embes:)),
n em1 ,n m2 = Ínt(in pet( Ent ex first
seeong n embes: ))
int (inpet( Tntex

)
hlem1 , num 2).

20. et is-pme Cn):


1f nc = 1 !
rcetun fyse

(2, int(n** o.s )):


fon i in anye

C e t nTue end):
n - g e (stont,
pmmes ):
det pind (Start , en t1
nem in
fo
end)
Preintl num,

ang e (i,1D)
Prin -prime - in
Department of Computer Science & Engineering
Faculty of Engineering &Technology (1TER)

2t. det fltom y(n):

ge(2,nt1):
fore i in ge

r e tu n Yeult

int (input('Ert eses a n umbes : ))

The faltorial ot 3 num } is


Preint (f
3tattoi ng (nun) . )
22. def point a ithntic -pogoein(fract_tem,
Conmon_ditference):
freit Fint 0 t eoms 6t the aruthmet c
pogrekion: e n d æ
to n in el10):
temz f t r t e r M tn Comm0n -

itteence

Pruntterm, ene )
frost tm, Co mm on dutfer en ce int (inpus ("
ERt es firt teym ot A P:"))

(input /"Eat or the com mon ditference


PreintoagitlmetC - porogossi on (fisttem,orrn
difference
Name:
Regd. Number:
Engineering
Departmentof Computer Scienco &
Technology (ITER)
Facultyof Engineering &

Staina ) ,
23. de vowel-iele es(inp ut

in enumeTat e/tnpt
in
ielex, chart
too
I0y:
Char in "a eivu AE
if
)
indlices . app en (in er
uolices

inpt " input_st?}:


ndices of vowels in
Print (f I ( i p u t - s t r ) } . ")

fvgwel -iuli'c es
ons(str-):
punetuati
Temove - Str-If ch :
24. def ch in
jorn ( ch Po
isajnum() )
")
("Ent ex a stoingi)
Gtr- > inp ut puntangs
ett e emo vi g a
Prile (f Sst?-? s(St9-). D
p u n e t e e t ion
Temove-

um 2):
cop me (numI, n
4ef a e -
While num 2: nUmnum
nwm 2,
num 2 >
n umi,
h u m b e : ' D

2 =
|Ent e fist
n m1 , num

Print(f{num and Snun? arte copime


Department of Computer Science &Engineering
Faculty of Engineering &Technology (ITER)

Sare- copmime (nunt,num 2)")

aE. qet eplace_ vo weas(st-)"


fo Cb in St .
i f ch in'aeioLSAELOD':

Cf3_ t7- .replace (ch, '*')

Sto- jnpu ('Enter &1 oing:")


a l the
Pree nt(f's7- atter
-Vowels
Vowey s with
:replace
(ser-)?")
det eon vert totext (num):

one )

2!

five

Seven

&:"ight
hene
Engineering
Department of Computer Science &&
Engineering & Technology
(ITER)
Faculty of

(t(n m)
St-num z
tertnm >

in Sto_n m!
for CA
it- tex t Lint(ch)7+
dig
tetum tert num
"))
int (inp ut Entey a numb er
-text (nem)? )
--> } Con vert - to
Praat (F fnem ?
(sto-):
det Shett

fo ch in Str

Itesu t a

eik ch

-else:

t ch (0vd (ch) t 1)
rresult

iput ( Entes )
Prtint (f seo
at ter
(str-). )
shitt-sting
ahead:
Department of Computer Science &Engineering
Faculty of Engineering &Technology (ITER)

a9. det ipexfet-umber (num ):

fetusn fayse

mge(, nwm I / 2 t 4):


fo i n

rC-ettem n m m

hum lt (inputEwt er e nunber: )


:is-perfet
num is aperfect n umb e
Pre nt (
number (n wm) )
30.
4et proel uet of - digits (num):

Prcoelt 1

wile nm>0

ret urn uet


pooelu

rnt (inp t E n t es a numb :

dig
{pooduct ot - igits (nwm)?)
Name: Regd. Nu

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy