Sie sind auf Seite 1von 6

Assignment2:

Programming
withPython

Due
Date:September23rd,
11:5PMGeneralInstructions:

1)
Allsubmissionshavetobeindividual,andwillbecheckedthroughTurnitinforplagiarism.
2)
CodingSchemeforthisassignmentis'2N-�-
b'.HonorCodeviolationsareinvestigatedaccordingly.
3)
PleaseremembertoincludeyournameandIDathetopoftheassignment.

4)
Please
submityour
pythoncode
as
Question_<number>.pyfilesi.e.,Question_1.py

forQuestion1andsoon.
5)
Therearetotalof11problems.
Attempt
allproblems.
6)
Uploadyoursubmissionsto�Assignment2Submission'folderonLMS.

1.
SupposethecoverpriceofabookisRs.200,but
bookstoresget
a25%discount.
ShippingcostsRs.40forthefirst
copyandRs.10foreachadditionalcopy.WriteaPythonprogramtocalculatethetotalwholesaleco
st
for60copies.[8Marks]

2.
Anumber,
x,isapowerofyifit
isdivisiblebyyandx/yisapowerofy.Writeafunction
inPythonthat
takesparametersxandyandreturnsTrueifxispowerofy.[8Marks]

3.
WriteafunctioninPythonthat
takesthreeparametersa,b,andcandreturnstheirgreatest
commondivisor.[8Marks]
4.
WriteaPythonscript
that
readsthecurrent
timeandconvertsit
toatimeofdayin
hours,minutes,andseconds,plusthenumberofdayssincetheepoch.[8Marks]

5.
WriteafunctioninPythonthat
takesthreeintegersasarguments,andthat
printseither�Yes�or�No�,dependingonwhetheryoucanorcannotformatrianglefromthegivenle
ngths.[8Marks]
Hint:Ifanyofthethreelengthsisgreaterthanthesumoftheothertwo,thenyoucannot
formtriangle.Otherwise,youcan.

6.
Thefollowingfunctionsareallintendedtocheckwhetherastringcontainsanyuppercaseletters
,but
atleast
someofthemarewrong.Foreachfunction,describewhat
thefunctionactuallydoes,assumingthat
theparameterisstring.[10Marks]
Note:Submit
pdffileforthisquestion

(a)
def
any_uppercase1(s):
forins:
ifc.isupper():
returnTrue
else:
returnFalseelse:
returnFalse

(b)
def
any_uppercase2(s):
forins:
if'c'.isupper():
return'True'else:
return'False'

(c)
def
any_uppercase3(s):
forins:
flagc.isupper()
returnflag

(d)
def
any_uppercase4(s):
flagFalseforins:
flagflagorc.isupper()
returnflag

(e)
def
any_uppercase5(s):
forins:
ifnot
c.isupper():
returnFalsereturnTrue

7.
WriteafunctioninPythonthat
takesalist
ofnumbersandreturnsthecumulativesum;
that
is,anewlist
wherethenthelement
isthesumofthefirst
n+1elementsfromtheoriginallist.[8Marks]
Example:

>>[1,2,3]
>>cumulative_sum(t)
[136]

8.
WriteaPythonprogramthat
readsafile,breakseachlineintowords,stripswhitespace
andpunctuationfromthewords,andconvertsthemtouppercase.[10Marks]
Hint:Thestringmoduleprovidesastringnamedwhitespace,whichcontainsspace,
tab,new-�-line,etc.,andpunctuationwhichcontainsthepunctuationcharacters.
>>import
string>>string.punctuation'!"#$%&'()*+,-�-./:;<=>?@[\]^_`{|}~'
Also,youmight
considerusingthestringmethodsstrip,replaceandtranslate.

9.
Writeaprogramthatsearchesadirectoryandallofitssubdirectoriesrecursively,and
returnslist
ofcompletepathsforallfileswithgivensuffix(like.mp3).[8Marks]
Hint:os.pathprovidesseveralusefulfunctionsformanipulatingfileandpathnames.
10)
AnalyzeEarthquakes

The National Earthquake Information Center (NEIC) determines the location and size
ofall significant earthquakes that occur worldwide and disseminates this
information
immediately to national and international agencies, scientists, critical
facilities, and thegeneral public. The NEIC compiles and provides to scientists and
to the public an
extensive seismic database that serves as a foundation for scientific research
through
the operation of modern digital national and global seismograph networks
andcooperative international agreements. The NEIC is the national data center and
archive
for earthquake information.
This dataset includes a record of the date, time, location, depth, magnitude, and
sourceof every earthquake with a reported magnitude 5.5 or higher since 1965.

Conduct
anEDAonthedataset
andtrytouncovermeaningfuland/orinterestinginsightsfromthedataset.

11)
Thedataset
containsdata
onIndiancities(sourcedfromGovt
ofIndia
website)andhasinformationabout
variouscharacteristics.
Columnsforthedataset
areasfollows:
'name_of_city':NameoftheCity'state_code':StateCodeoftheCity'state_name':StateNameof
theCity'dist_code':District
Codewherethecitybelongs(99meansmultipledistrict
)
'population_total':TotalPopulation'population_male':MalePopulation'population_femal
e':FemalePopulation'0-�-6_population_total'0-�-6AgeTotalPopulation'0-�-
6_population_male':0-�-6AgeMalePopulation'0-�-6_population_female':0-�-
6AgeFemalePopulation'literates_total':TotalLiterates'literates_male':MaleLiterates'
literates_female':FemaleLiterates'sex_ratio':SexRatio'child_sex_ratio':Sexratioin0-
�-6
'effective_literacy_rate_total':LiteracyrateoverAge7'effective_literacy_rate_male':
MaleLiteracyrateoverAge7'effective_literacy_rate_female':FemaleLiteracyrateoverAge7
'location':Lat,Lng'total_graduates':TotalNumberofGraduates'male_graduates':MaleGrad
uates'female_graduates':FemaleGraduates

Conduct
anEDAonthedataset
andtrytouncovermeaningfuland/orinterestinginsightsfromthedataset.Beforeconductingth
eEDAstatethequestionsthat
youwouldwant
toaddressfromthedataset,andthenconduct
analysesaccordingly.

Das könnte Ihnen auch gefallen