CompSci 100 Prog Design and Analysis II October 14, 2010 Prof. Rodger CompSci 100, Fall 20101.
CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd...
-
Upload
annis-allison -
Category
Documents
-
view
223 -
download
0
description
Transcript of CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd...
CompSci 101Introduction to Computer Science
March 31, 2015
Prof. Rodger
Thanks to Elizabeth Dowd for giving this lecture
Reviewforexam
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
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 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 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
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
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
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
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?
number is 5 , school is dukeIn testone, num is 4 , s is HelloAfter call to testone, number is 5 , school is duke
OUTPUT
Parameter and Argument have the same name
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
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
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]
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)
Parameter and Argument have the same name
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)]
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)]
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])
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)])
Now go over Test Practice problems