CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd...

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

description

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

Transcript of CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd...

Page 1: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

CompSci 101Introduction to Computer Science

March 31, 2015

Prof. Rodger

Thanks to Elizabeth Dowd for giving this lecture

Reviewforexam

Page 2: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Announcements• Exam 2 is Thursday• Assignment 7 is out• APT 8 is due today• Review Session with Prof. Rodger

– Wed. 5:30pm, LSRC B101

• Finish lecture notes from last time

Page 3: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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

Page 4: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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

Page 5: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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):

Choose “no c”, most words, 21

Only 2 words of this typeOnly 2 words of this type

Only 8 words of this type

Page 6: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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

CompSci 101 Spring 2015 6

Page 7: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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 recursionCompSci 101 Spring 2015 7

Page 8: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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

CompSci 101 Spring 2015 8

Page 9: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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?

Page 10: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Page 11: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

number is 5 , school is dukeIn testone, num is 4 , s is HelloAfter call to testone, number is 5 , school is duke

OUTPUT

Page 12: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Parameter and Argument have the same name

Page 13: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Parameter and Argument have the same name

OUTPUTnum is 2 , s is catIn testone, num is 4 , s is HelloAfter call to testone, num is 2 , s is cat

Page 14: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Page 15: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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]

Page 16: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Parameter and Argument have the same name

Page 17: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Parameter and Argument have the same name

OUTPUTlista 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]

Page 18: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Page 19: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

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

Page 20: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Parameter and Argument have the same name

Page 21: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Parameter and Argument have the same name

OUTPUTlista is [(4, 5, 2), (3, 2), (3, 4)]In testfour, lista is [(4, 5, 2), (3, 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)]

Page 22: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Page 23: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

OUTPUT

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

Page 24: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Page 25: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

OUTPUTmyset is set([2, 4, 5])In testfive, seta 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])

Page 26: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
Page 27: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

OUTPUTmyset is set([(3, 2), (5, 2, 1), (4, 3)])In testsix, seta 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)])

Page 28: CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.

Now go over Test Practice problems