0% found this document useful (0 votes)
42 views12 pages

Python (Assignment 1) Shubh

Pythen is an easy to learn, high-level and dynamic programming language. It has a large standard library, is extensible and supports multiple programming paradigms. The main features of Python include indentation for code blocks, various data types like integers, floats, strings, lists, tuples, dictionaries, sets and classes. To run a Python script, it is edited and saved with a .py extension, then executed using the Python command in the terminal or IDE. Operators in Python allow expressions to be evaluated through precedence and associativity rules.

Uploaded by

bikku9751
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
42 views12 pages

Python (Assignment 1) Shubh

Pythen is an easy to learn, high-level and dynamic programming language. It has a large standard library, is extensible and supports multiple programming paradigms. The main features of Python include indentation for code blocks, various data types like integers, floats, strings, lists, tuples, dictionaries, sets and classes. To run a Python script, it is edited and saved with a .py extension, then executed using the Python command in the terminal or IDE. Operators in Python allow expressions to be evaluated through precedence and associativity rules.

Uploaded by

bikku9751
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

DATE:

Asignmnt (Unit 4)
Sectien -A
hat ae the main featuea of fythen ?
The main atunea g pythen ant
c) Easy to Leanm ())Fxtensue featune
D fasy te Code (vin) High Jkusel iaiguage
Sntrjhactet iangageN) Datakas. sot
prcgam
iw) dhct ariented l) Lazge sndard library
LC)Cus platkenm on) Dynauc Tyjed angage
pueu afan jintnadtùle shellin Python9
2 lhat i The plee
> The pythen ntnactiu Ahll preucles proqammi
qick ay execute cemmand and tyQt
n tet code ithoutcating a fle
3 Gplaisn the imþartance of centation in Pthen 9
Pyttuen inndentatin i a uay tillig a Pytnem
mtabtn that Thu greuyb af statunias belongs to a
prticulan block coda A block u a cenbinatien
6 al theeestatesmemt

Sduntity afexates.
both ti checta
andhar the Sme mmDy docahen

5. uite a
Rytnen scipt that
Amputnd pinta a prrienaliged elcemeeinage
PAGE NO.:
DATE:

name)
ame.inhut C Enter your
your
print Welcome",name)
nomesShubh
Qutput Enter your nor
Welcome Shubh.

Section-B
llhat anu the basic featue o yM prgramming
language? Explain hu prozes f editing, sauing
and zumning a
Tha baic feature o ythen prcgaanamng danguage
fordalle language Stncancl lilbray,High-laual
Languagt, kay to leann amd uit, Byananue Janguag
Extinaible language and ntujuiBecl langage
Th pxcziLi editing sang amdnninga futen
BCibt m a text editor 6a IDE:
4fditingu pythen scibt
nw file ar efen an exiting Pyten scut
pite luith a'-py'extencien)
LAlute edlt ewr pytnen codle mthe edter FrUTe
Hnat te code ieceuclly lenmatted, indudng
preper ndentatiom

2. Sauing tmu pyttonseilt: py' extensitn


Cheece a mianingful nane fer u file tmat
ellecteit punloe
DATE:

3 Runnisg u pytnen zoist:


built- in running unetienality
CemnnaNnd inu/Terminal
Execute
butten that yslL Canclick to run tne sibt
Uing tucemaand Linutnminal! nauigate to tu

we tne pyten! cemmand foliouud by script


tilianane pythen scijt mit py
2
DixcusA tu Aistoy -and euolutien pytncn prcqpammng
lamguage 4lustrate thu ditinetien betueen
statamuat and epaeiens in pythen uing suitable
lxamble
Pytien i idly wsd genal-puzjpesa,high leel
prognammung lamquage 9t siainitiay duiged by
ude van Reaum in 1991 ard deuilqjed by Pythen
Battuaufandation uaa mainydielo pecl fer
emphasi on cocd ead abilltyamd st syuax alau.
Evolutien Pythen:
gthonlaid it koundatin n thu late 980 & The
Uartanted m pecemmbt 989
maplementation of pytn
by Caudo an LosumAt cwT m Netheiamd sn
Febuay 1991 Guido Nan Eosmpubikhed te ce
Uakeli 0.9.0)Sn 1994, fsthen A:0 asHleased
Luthnuw feater Lite lambdanabhun and ruduca.
nuduce
Iyhen oo addid nauw jeatues ike iktcenybrihinaen ,
gulagecollectio Bycte On Decemaber 3, 2008
fytuen caignecd th nectily
PAGE NO.:
DATE

Stutemeta in Pythen:
Sn pytLteatatenntnt jsan mtUten That
Pytun threter ca execute. Thine ae
Aiiqnnnt ztatenins
cenditienalatateasunts Loeping statiment ete
teken laanactr NENLINE sed toD p d a
statumunt in pytiucn Aigilin that each line a
fytuen scubt containi a Atatemeat
Exanble: # Statement
print ( Hello tortd')
StateNennt 2

# Statenent 3
(x)
print
Cutput: Hello world
206

ebrexiena in Pytnen
ia a combmaton s cpenats and
openans Ihat tnpruttd to prcduce &tm sta
Vaue

Eane:
print (x)
Gutputl6.3
3 (a)lite a prcgaamm im pythen that accpts tue
numbers em hu seeand dicphy: hin
sumy
mctpcduct and quctient.
diylay uaus beferu suopingand altn
a= int input ( fnter first number ))
bmt Cinbut (' Entcr Secord number ))
print CSun ab)
print C Difitrtnceni
peint ( Product , ab)
print CQuotient " a b )

Cutput i Enter tirst number: to


Enter Second number 2
Sum i 12
Difference:
Praduct 20
Quatient 5.0

cb P= int Cinbut " Please enter yalue for P: " )


Qint Cinbut Please entr yalue for Q" ) )
print ( The valve cf Pbetore Ao ppìng :" P)
print The volue of Q before Aabþing

Q A
print C The. Valie of P alttcCAwaphiag )
print C' Ihe value of.QatttrAuaphing)
Cuthut:Pltase enter.valvefor P: S
Please enter volwe tor
The Nalue of before sw apping 15
The yelue af @befateduobing2
The volue of P afterauiabping 2
PAGE NO.:
DATE:

The valve of Qafter Awaphing5


Sechey-C
4
Discuss tu concest o< cherato'a in Iythen uiat do

exectien n expreziens teugh pradnca and


soiatiity 2 Bueide an eKommple to ilstate thia
The opezate s a synbal that perfezmia ecilic

atlinition Cpuatoi sUs as Ti fandatien sken


hich Jzic dis censtucted jn a peqnam i
pkogmamming ianguage
Membiip Opeator i Thu mmabesip a ua
AMiidi a pytnen data stuctuu cam be
pythen mnbeshib operators The 8Lutt tuue
Ihe aluu in thi Lata stuctuze _othehie
it atuN fale
in'oherator: he first apeand tamact be koumdin tu
sicond oenandt ealuated to be tuu
Ain'ohotater 1 th fist openandà net pisLnt i
obenandu eualuatien is tu

by kath penator precdnce and anoiatiuity


Bucdencei Oherates uth ighr precedance are eala

in any gen Loqyial or aithmatioespreuien


fn Fxanme n the expussion,
3+4 *5
DATE:

mutiblicatim C*') has a highrprucedene than


additi C4)so S j evaluatccl pbut sulting

Assaciatiuity oheatos kauu tne sam prucademe,thu


ASGCiatiuity dotuisea tu grcler in hich tty
eualuattd Asociatiuty aidi in determhng Tu soquunc
oenatens uhem tuo operatos share the xam
picrity . The cinectien in uhich ay guan eprsien
uith meu than enu opeatan haiing tu same pucedenc
i saSsEsed assessid is associatiuity Alnpst euexy eperato
aRiGciatiu frem it to ght
for exammple: Sn tne exbetibn

ealuated pirst, 88lting ln2and thun


eualuateod to gi he pinal s e t !

2Eblain tu ciferunt aata typesavailable n pythen


and puouide xambles far each tou deu type cemenien
uock n pythtn? Ereudeexamblesto cenentrate tye
conmenuninhytnon.
The difeant datatypes alaialble n pyt8n a i
Nuomexic Cint.poat , Cenhlex)
)
Sequna Type CString list , Tuple)
D Boclean
QV) Set
(v) Ditienany
PAGE NO.
DATE:

puset: ite dat that a a nmMTValue.


Anumeric vae can be enttigra heatno
Dumber -ee Cemplex nmbes
Snttgens : 7his value i neptuented by nt clau 4

Eloat i This valu ie cpreeatectbypleat clas.


ypantatien in speciiud byyadecimot psat
puiad
Connhlex Nuanbeis A ceniblex nurDtlek a
abeesenteal by s conplex ass ttid asbecited

Exaable'
print ("Tþe ot a"tta
b=5-0
prigtTyhe ofbi"tye
Cb)
print (" Ty of e tyþe Co))
Outht: T4be of a' <class int'>
Tpe ofbsclass Alaat'>
Tape of c: <clasCemplec>
HD Sequnte Data Type The siquemce data type
jmpsthtn thu ordiud coLleche ulan
dillered data typu Sequsrcealleue stel
ogaiged and
Thee
Fytnen:
String Shring
Shring
pestathng umicode
m pythcn ae anay
clanactere Asting
bytes.
a
DATE:

collectien o nnou chanactes pudn a


sngltqcte , cleulble qucte ts tuplkquuete
Exanyle: Str tring using doole qyuctus.
prnt (str)
Ouut: stuing using double aqu ctts
" List ;: istaa i t ike aiaysdeclac in ctut
languageA
be te sanu type
sassble list CL hì, Python" 21
print Ctype CIist))
print Chist)
Outputi <class ist'>
CLhiython',21

Tuple i A tye csllectien f Pyten


ei alo an zdued
Gljecls Thu tmly ailerunck betueem a tuple and a
ist that tuples ar anutable ie tuples cannot

be modifud alte it i cheated


tup hi"" Lthon", 2)
print CAyhetop))
print Ctp)
Qutputi<lasstuple'>
(hthen'2)
iiD Boelean Data Tyhe pata tyhe ith en e the tLo
false
print Ctyhe CTrue))
priat Cyhe (false))
Print false
PAGE N0.:
DATE:

Ccloss bool
< class bool
Neme Error namne'false' s notdefineA

datatye: n pytiLen, a et s an nondred


M) Set tvablemutaHe
callcten of datatfpe that
and a no dusicate eleent
Fxanblei Set = seto
Set 2=James'2,3, Rthon' )
print Cset 2)
Outhut:3,2JamesPetthon

) Dictienay dake type' A dictienay pytuen an


erdued cllcien aata vale ec to steL
data Valusike a mas , Lnike othe Data Tybi
Hat ald ey valueas an element a
dichionazy holde a key-vale pain
Eanple d= Jimmy_2:Ales'_:Jahn qike
print(d)
print 1st nameis '+ dCn)
print (" 2nd name is" t tCu1)
print (d keysc))
print Cdvalves C) )
Quttput lst neme is
is Jimm
2nd nome is nike
Jimy,2: Alex'3'John
dictkeqs (I,2,3,y1)
dict- values CIJimnmyAlex Tabn,
Tyhe Cenuien im Aytuen
Thu act o changing an obiect is datotype k knel
FACNO :
DATE:

4 nlict tye comuiom n thi, thu


ntenpzte autenaticaly cenrde En data tyfe
ancthdheutiauyLer clume t

peint C"is atyhe of tyetx)


pcint "y is otyhe ilecy))
of
printtz)
print C"z is atype of:"tyhe (z)
Outhut:
y S a tye Gf < class float>
26-6

) Geblicit type C¡nwersibn : Sn tiA,dat the is manually


changed by as pes tun requuweamnt
fxamale S=

pint C After converting to jateger base oi end "


pcintc
e = floot (s)
pint C After converting to fioat ! end)
print (e
Outfuti After converting to integtr base 2 1816
After Convertin, to ftoat oo10 o

3 ihatwil be tne eutfpt f thu pelloing tatemente


2re exected n pytnen nteractive
PAGE NO.:
DATE:

) abs C-27 cb min(t02,22o 130)


max -, -4,-l0) d max AB2)
max (a B 2 ) f) round Cl6)
math:lop C16,2) ch) math- floor Cl8)
g) math ceil Ck2) j) math scos Cnmath pi
) print ("oo,d3format C1234 S 6 18))
(a) abs (-2)
Output : 2
b) min Clo2,220, 136)
output: t02
(c) max ( , -4 -l0)

Nax(A2')

Ce) max a' B 2 ' )


Cutput
f round (1'6)
outhut: 2
9) math ceil (l:2)
Cutput i 2
chy moath floor Ctss)

) math:log Cl6,2)
oulput
G math:cosmath'pi)

tk) print o6d format (i234567 g))


Outpu 12,34s,618

You might also like