Comp Sci 101 Introduction to Computer Science March

  • Slides: 28
Download presentation
Comp. Sci 101 Introduction to Computer Science March 31, 2015 Review for exam Prof.

Comp. Sci 101 Introduction to Computer Science March 31, 2015 Review for exam Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture

Announcements • • Exam 2 is Thursday Assignment 7 is out APT 8 is

Announcements • • Exam 2 is Thursday Assignment 7 is out APT 8 is due today Review Session with Prof. Rodger – Wed. 5: 30 pm, LSRC B 101 • Finish lecture notes from last time

Snarky Hangman • Version of Hangman that is hard to win. • Program keeps

Snarky Hangman • Version of Hangman that is hard to win. • Program keeps changing secret word to make it hard to guess! • User never knows! • Once a letter is chosen and shown in a location, program picks from words that only have that letter in that location • Program smart to pick from largest group of words available

Snarky Hangman - Dictionary • Builds a dictionary of categories • Start with list

Snarky Hangman - Dictionary • Builds a dictionary of categories • Start with list of words of correct size • Repeat – User picks a letter – Make dictionary of categories based on letter – New list of words is largest category • Matched letters • Letters guessed by not chosen • List shrinks in size each time

Snarky Hangman Example • Possible scenerio after several rounds • You currently have a

Snarky Hangman Example • Possible scenerio after several rounds • You currently have a list of all words with u the second letter. From that build a dictionary of list of words with no c and with c in different places (show count of number of words in each list): Only 2 words of this type Choose “no c”, most words, 21 Only 8 words of this type

Exam logistics • Only need a pen or pencil • No scratch paper •

Exam logistics • Only need a pen or pencil • No scratch paper • See the reference sheet of Python information you will get with the test (see resources page) • Closed book, closed notes, closed neighbor • Covers lecture, lab and assigned reading • Have put old quizzes back up as quiz review – This is NOT for a grade, for studying only Comp. Sci 101 Spring 2015 6

Understand old and new topics • Old topics: if, for, while, lists, strings •

Understand old and new topics • Old topics: if, for, while, lists, strings • list comprehension, enumerate • Files – write code - Will give you a file already opened and ready for reading • Sets, Dictionaries – write code – create and use • Understand items on Python review sheet on resources page • HAVE NOT COVERED TOPICS – regular expressions or recursion Comp. Sci 101 Spring 2015 7

The best way to study • Write code on paper! • Resources page has

The best way to study • Write code on paper! • Resources page has old tests and solutions – Try writing code, then look at solutions • Rewrite an APT • Rewrite code we did in lecture • Rewrite code we did in classwork or lab Comp. Sci 101 Spring 2015 8

Think about how parameters work • Look at variables before passed to a method

Think about how parameters work • Look at variables before passed to a method • What happens to them after they are passed? • Can the parameter and argument have the same name?

OUTPUT number is 5 , school is duke In testone, num is 4 ,

OUTPUT number is 5 , school is duke In testone, num is 4 , s is Hello After call to testone, number is 5 , school is duke

Parameter and Argument have the same name

Parameter and Argument have the same name

Parameter and Argument have the same name OUTPUT num is 2 , s is

Parameter and Argument have the same name OUTPUT num is 2 , s is cat In testone, num is 4 , s is Hello After call to testone, num is 2 , s is cat

OUTPUT nums is [4, 3, 8, 5] In testtwo, lista is [4, 3, 8,

OUTPUT nums is [4, 3, 8, 5] In testtwo, lista is [4, 3, 8, 5, 6] After call to testtwo, nums is [4, 3, 8, 5, 6]

Parameter and Argument have the same name

Parameter and Argument have the same name

Parameter and Argument have the same name OUTPUT lista is [4, 3, 8, 5]

Parameter and Argument have the same name OUTPUT lista is [4, 3, 8, 5] In testtwo, lista is [4, 3, 8, 5, 6] After call to testtwo, lista is [4, 3, 8, 5, 6]

OUTPUT lista is (4, In testthree, after call to 5, 2) lista is (4,

OUTPUT lista is (4, In testthree, after call to 5, 2) lista is (4, 5, 2) lista is (7, 1, 3) testthree, lista is (4, 5, 2)

Parameter and Argument have the same name

Parameter and Argument have the same name

Parameter and Argument have the same name OUTPUT lista is [(4, 5, 2), (3,

Parameter and Argument have the same name OUTPUT lista is [(4, 5, 2), (3, 4)] In testfour, lista is [(4, 5, 2), (4, 3), (3, 4)] after call to testfour, lista is [(4, 5, 2), (4, 3), (3, 4)]

OUTPUT mylist is [(4, 5, 2), (3, 2), In testfour, lista is [(4, 5,

OUTPUT mylist is [(4, 5, 2), (3, 2), In testfour, lista is [(4, 5, after call to testfour, mylist (3, 2), is 4)] (3, 2), (3, 4)] (4, 3), (3, 4)] [(4, 5, 2), (4, 3), (3, 4)]

OUTPUT myset is set([2, 4, 5]) In testfive, seta is set([2, 3, 4, 5])

OUTPUT myset is set([2, 4, 5]) In testfive, seta is set([2, 3, 4, 5]) after call to testfive, myset is set([2, 3, 4, 5])

OUTPUT myset is set([(3, 2), (5, 2, 1), (4, 3)]) In testsix, seta is

OUTPUT myset is set([(3, 2), (5, 2, 1), (4, 3)]) In testsix, seta is set([(5, 8), (3, 2), (5, 2, 1), (4, 3)]) after call to testsix, myset is set([(5, 8), (3, 2), (5, 2, 1), (4, 3)])

Now go over Test Practice problems

Now go over Test Practice problems