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

Python Assignment 2

The document is an assignment from Silver Oak University that covers various programming concepts in Python, including functions, type conversion, recursion, lambda functions, and object-oriented programming. It explains the definitions and uses of these concepts, along with examples and syntax. The document also touches on advanced topics like inheritance, polymorphism, and database interaction using Python with SQL.

Uploaded by

hastilakhani569
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)
30 views19 pages

Python Assignment 2

The document is an assignment from Silver Oak University that covers various programming concepts in Python, including functions, type conversion, recursion, lambda functions, and object-oriented programming. It explains the definitions and uses of these concepts, along with examples and syntax. The document also touches on advanced topics like inheritance, polymorphism, and database interaction using Python with SQL.

Uploaded by

hastilakhani569
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

SILVER OAK UNIVERSITY

EDUCATION TOINNOVATION
Date
Page No. : ...1

:
Assignment-2
Unit 3 FunehonS { Recursion

what is funcion in pythen Exploin hoo a tuncin


is dfin and Called

ans. A funcien în pythen is reuseble block o


Codo Hhat perforrns a
ode
specific tes k .funchey
helas in Angonning ound Uding
Sdundancy

Defining

def funcnome Cpamamot ens):


# funchon- bocy

heturn alue

Calling funcien

netwnn f Hello, noame?

tint eet Ramanand '")) H func Cal

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. ...?...
3

2 waat is type convens ion in python ? Can ros


n

eamp eohe tyre conuensiom


is

ns COnwasion:
Type

honging CA Voiable forom


Cnothen python is a

dynatealy tynd lanauoqo hut Somitims


to enueitty eouet wawes to
entoa
whent neccesSOy.
is

ponforming Dnnaion
mignd nood to Con west

Meoing functì ennequinements


Soe Aunchos

Data fmatting
when eading dae from ile os datebases
neo to ttue doute to the
nolate

Messag I om + socge)t yeans old"


PintCMess ag) www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. : ...3.

Q3: whatis necws ion


Simpu erompl nucwnsiue

Recwnsien is
prgrmming techuiewe whenu
funeHn

Recsl funcim eampu


bA classic erampu is Cal culating thofuctoicd
numo.
olef fuctorial eni

eLse
netwn n fcactorialCn-1)

Nesult = factoial 5)
paint (oesut)

Base Cases The leh diti Gn that stos tae aeoruwiom.

HUf in fniety leading to

Recusiue calI Tue funcien ealliua itelf


npute
www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date Page No. : .....

what lambda func hon in python


provicle leembda funehm
that adds tuo num bens

CLns. Lambda Functioy Small noymow


Cunamed) funcioni deind sing tie
Knoun
iulineFunchom heca wse tey ane tpically
olained and wed in

amboa funcivn eyample


A loLVYbda fune on to edo tuo nwmbes :

hesult = add53)
punt resut)

DefineS tue anenymOus paanmutns

X+Yi Tu cXprssien that is ealuaed

www.silveroakuni.ac.in
SILVEROAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. : ...5........

Gheymous functions 4 ho do
Hhey
diffen forom funckim in python

CUns Awoumous funeisws Func honj wiheout


functi Gwy a

to Cneat fun cios

Diffensne fromngulan Func ions

Rgulan fnchs he dulinad

Fucnchies dist hae a

Sytz hnchow haw e mou


RegalaA
wncin Ruclu
atar
Span
Anoy
ith
mulhple
mows
is
funchoM
4

hau
3tetemets,

Realen hneh'os
ai atis
hirt,simp lu nenaions wte
funehom delini ion sD

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date :
Page No. :...6.

Symbol n

escamyale itn p anametes

A de (OratoY
enhane henchom clen
Clo you to
Cunc hon extrafun
eionaliy
fnhim executocd wthout dine oty
chagig tue odginadFunches cocle
using te 6osymbol:

Tue Symbol is wsec to cppy


to a funchi na CyutaH Juga tna t

torator
ele

do f my deoratY (prefix)

bnp ut (Ent

(e my_derutr
def inal C):
pass
www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. :....

unit: 4 Dhet clesses

Fzplain the key tenms sed objeck- onente


in

ragramming (0op)in pyth on, such Cu casses


hjecfmetaodls

A class is iko
templat fos CrSeatig ohiects, It lefines
taeshuctune p behawioun thet Dbects
Sthot class

Dojects

Aa abject

ponforms uction otinad lay tne class.

Methoc
A mothod is ca tuncion that s oJsoiatos
Hth an wey For cn 0bject
to intenact witth its dat or pen horm

Methbds Bnate Mehecthe


hject'g cate
4 Can

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. :2

02

CLVS •stante obiects

clate

Ohitcti

toma ically n te
claxis

clos Ohiect Cen aau thibutus tt ere

shaned Qmang festentu

in
www.silveroakuni.ac.
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No.: .....4.

How lo
ou dhey
delc
oject
ethad
in pytaen
in
ahad is
aject des buc hicn)

Ln. Dhject
Destucti

• Python ses automohit qam bog celechn h

nynned by awy part tue p ram


Qutoma hicaly
hecluims the meminy DCupiac hy trat Ohjer

cu lso expicity delell ouh Sbject tsing


tis
quanLte immedci! dstucin os eCUObeg
Aelloctien migat be odolayeo.

--del--c Metho d

metd(DO call tedetctu


is aspecial methd eL QLtonn atical
palled sen
ebject is Cbaut o he
Celleeter

BLLOw) tou to penfomm claue tusle


be fon distyed

Mana9pmout geAy olis co ogedde to


Unpredictbe Hming t
www.silveroakuni.ac.in
SILVER OAKUNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. : ..!.0..

Q bohet CLCCess modifiens inpython ?


Explain tu dEfenence
publie memoens.

Access modifes in python


accessibiiy hr clous
en
membe
thes

acces modihns
pblic

piate (-priveti )
Public Memb ensa
pubic mmbes ane accesible bom ciysee
betth fuside etsido e clas

ponate Membens

pagixd
Cannot heaccesed oiret fm
aticle
Examu
cless
de f faitea (sef brend )
Sef. brand sbrend t public Athibte

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. :.....1,..

clef displey (serf)i branl3


caY brand i seIE.

Class Carnolel
fuit- model): CseE
clef
sef.-mocle= no de #pivete Atibte
def qet- model CseLf)
Se IE=mod

phiuf tj b rend )
e
ACcessib
eDbj1 Car m odel Foy tunen)

will saise
psu'nt (obj1. qetmodolc2)
memen methot.
Access iwg pnnete a

what is fuheniteunce fa Python y f hos eloes


an ecame
4 clas iaheeitun c

Tnhentane
Iaher te n ce i6 cn Oop cncnt tht cellos a

class CChl) to inhenit pties 4 e tho

Eno m

Codo
Paomettng msdulan pegamming

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date Page No. : .J.L

:
T m nheni tanu
1 Sing Iaheiten e

3 Mulileel lhitone
Heiraicaheiten ce

H ponent cls
Class Anim a

init-- (self, namu)


d
Self naYu = nm
dut Seak (sef)
htwn 1 m ake Sounds

Ruhenihng fomAnimd
Dg
d Seak Cself):
AetnBusik parn etho

name) # nheie Attmbut


pint Cob). Snekc) 4

meet

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. : ....1.3..

uheri teun u

AroidS co cle oiction


Enhanw Moduliy f Malutanaiity
Promotes warcdcot nlatiy is
oetulen

Qb Exlain polymois m inpythen ith cn


LOum. Ho withmthsl

Polymorphism in pytnin
polymoTp hism llo
lesses to be tne ate a
Cem&n
s otecH
bcse cass

poly morpism
mathod ueidig thhl
Cthougla methe
n python)
aloaoug do not surt
Methot Duing
Metnad ouenidiwg cs
Specikie fmlemutatieo
Metho

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date :
Page No.: ...J.5.
clasS
de sound C sec):
netn Som0 qenenic Sound"

Sowndl see)
tn

poly mop wsm


Makl- Sond Cbird):
print Cbind Sondc))

(aw cas

Www.silveroakuni.ac.in
SILVEROAK UNIVERSITY
EDUCATION TO INNOVATION
Date : ....PageNo. : ...[5....

unit 5i Exeepies Handings f

Pythen laith SQL:


Q1.
hat is PL in Python, ho do nou iwstal
apythe packag wsi ng pip2

Pythtn am t Pythe
pakag
fython package usi g pip

pip install Pecka hemi


For eq to istall numpyi
P'p iwtall numPy
eheciwy lwtuled puckaei
Pip- vnsim

\wstll--ungraole pip

stalli ng packal
package-rane
www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date: Page No. :.

How Cen
gau we pytnon to intenact uith

esta us h C Cenction

Pyton intenacti th a MysQL dathases


tue
aing Mysalcennctrpythtn packo

Conct ne

wnsoY

Step 1 lwtll MysQl Cennector


pip iwwtal Mysql-a Cennect-pythn

module fn pyth
import mysqL. Connnectu

nechn =myssl.connecY. conet


stlochost

Cunser ohjeet

C&nne cin CunsoTC

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. :....11.

SQL Quies

Cwrs ecelCsHo DATABAS Es)


fos clb in CunsoY

Pnt Cdb)

Sepi Clo set cownichin

connechen- cosecs

13. Fxplein hous to iwstall the MySaL conctun


hen pytn, what comman
Pwstelti on

Cs comnectes
lonect pyhon anicatis with MyaL
datoayes

1 lwtallati cn Comnd oingLP


Pie istall mysqd-conne chirc eythen

2
Veni yi ug lstellatin

mot mycqi. connectun


piat My sql Connech lstas Succey

www.silveroakuni.ac.in
SILVER OAK UNIVERSITY
EDUCATION TOINNOVATION
Date:
Page No. :........

siug Python.

Slep 1 lwstall MYsqL Cennectu

slepz nrt t ysgcnect mod

MysQl Sehes

dateut
Cettim dteb(oeaticn

tu csmeiom.
How do
Ceating
wsina pyton Mysal

Cso Qxecute c meth9


Conecim.

Ecaml eatiy
pytm
www.silveroakuni.ac. in
SILVER OAK UNIVERSITY
EDUCATION TO INNOVATION
Date : Page No. :...)A....

import Mysql Cennct

# (onneet to te database

C&metn mysg. Connucts. connctC


host: (0celhos t

olatebe mydatabae
Csos Cownehin. cnsrC
aeato tebu

CREATE tABLE Studeuts (


INT Auto incremeut pimay key
VALCHAR (255)

gTade VARCHAR Ceo )

CusUro exeto (cattase quer)

lose tu Comnectiem

www.silveroakuni.ac. in

You might also like