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

24
LING 408/508: Programming for Linguists Lecture 24 November 30 th

Upload: others

Post on 26-Sep-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

LING408/508:ProgrammingforLinguists

Lecture24

November30th

Page 2: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Administrivia

•  Youshouldbeworkingonyourprogrammingproject

•  Homework11today– opJonal– easyopportunitytomakeuppoints– dueFridaynightbymidnight

Page 3: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

LastTime•  Chapter6:

–  CoolprogramtointeracJvelyspecifyatriangleandcalculateitsperimeter

Page 4: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

LastTime

Page 5: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

LastTime•  Chapter7:DecisionStructures

–  if <condition>: !<body> !

–  elif <condition>: !<body> !

–  else: !<body> !

–  try: !<body> !

–  except <error>: !<body> !

–  except: !<body>!

Page 6: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Today'sTopics

•  Chapter8:LoopStructuresandBooleans

Page 7: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

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

Page 8: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Loops•  Alreadyseenforloops:

•  while<condiJon>:<body>

sameas

Page 9: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Loops

Problem:keepsprompJngforyes/no

Page 10: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

LoopsabeWerprogram:•  usesraw_inputandeval !•  whilelooptestsforemptystring

Page 11: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Loops

Emptyline:includesanewline"\n"Endoffile:""

Page 12: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Loops

mulJplenumbersononelineseparatedbycommas

Page 13: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

LoopandaHalf

Page 14: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

CondiJons

•  bool:TrueorFalse

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

Page 15: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

comparisons

•  CompoundcondiJonal:not <expr> !

notthesameas

Page 16: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

comparisons

•  Defaultvaluesusingbooleans:

withimplicitcoercionofstringtobool

Page 17: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

comparisons

•  Defaultvaluesusingbooleans:

aonelinewonder!(originalcodehad5lines)

Page 18: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Homework11

•  ImplementanytwooftheProgrammingProblemsinChapter8(pp.262–264)

Page 19: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Chapter9

Page 20: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Chapter9

•  RacquetballsimulaJonprogram– useslibrarymodulerandom

Page 21: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Chapter9

Page 22: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Chapter9

Page 23: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Chapter9

Page 24: LING 408/508: Programming for Linguistssandiway/ling508-15/lecture24.pdf · Last Time • Chapter 6: – Cool program to interacJvely specify a triangle and calculate its perimeter

Chapter9