ling 408/508: programming for linguistssandiway/ling508-15/lecture24.pdf · last time • chapter...

Post on 26-Sep-2020

9 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

LING408/508:ProgrammingforLinguists

Lecture24

November30th

Administrivia

•  Youshouldbeworkingonyourprogrammingproject

•  Homework11today– opJonal– easyopportunitytomakeuppoints– dueFridaynightbymidnight

LastTime•  Chapter6:

–  CoolprogramtointeracJvelyspecifyatriangleandcalculateitsperimeter

LastTime

LastTime•  Chapter7:DecisionStructures

–  if <condition>: !<body> !

–  elif <condition>: !<body> !

–  else: !<body> !

–  try: !<body> !

–  except <error>: !<body> !

–  except: !<body>!

Today'sTopics

•  Chapter8:LoopStructuresandBooleans

condiJonalexecuJon•  variable:__name__ !FileexecuJon/import•  python file.py __name__ is '__main__' !•  import file.py __name__ is 'file' !

Loops•  Alreadyseenforloops:

•  while<condiJon>:<body>

sameas

Loops

Problem:keepsprompJngforyes/no

LoopsabeWerprogram:•  usesraw_inputandeval !•  whilelooptestsforemptystring

Loops

Emptyline:includesanewline"\n"Endoffile:""

Loops

mulJplenumbersononelineseparatedbycommas

LoopandaHalf

CondiJons

•  bool:TrueorFalse

Javascript:•  undefined,null,NaN,0and""arefalse•  everythingelsewithavalueistrue

comparisons

•  CompoundcondiJonal:not <expr> !

notthesameas

comparisons

•  Defaultvaluesusingbooleans:

withimplicitcoercionofstringtobool

comparisons

•  Defaultvaluesusingbooleans:

aonelinewonder!(originalcodehad5lines)

Homework11

•  ImplementanytwooftheProgrammingProblemsinChapter8(pp.262–264)

Chapter9

Chapter9

•  RacquetballsimulaJonprogram– useslibrarymodulerandom

Chapter9

Chapter9

Chapter9

Chapter9

top related