Agenda Announcements Structure Tuple review APT and for loops - - PowerPoint PPT Presentation

agenda
SMART_READER_LITE
LIVE PREVIEW

Agenda Announcements Structure Tuple review APT and for loops - - PowerPoint PPT Presentation

Agenda Announcements Structure Tuple review APT and for loops 1/14/2013 CompSci101 Peter Lorensen 1 Variable Type High level Value Modules Functions( ) Functions( ) Datastructures code Variables (String) Datastructures


slide-1
SLIDE 1

Agenda

  • Announcements
  • Structure
  • Tuple review
  • APT and for loops

1/14/2013 CompSci101 Peter Lorensen 1

slide-2
SLIDE 2

High level Modules Functions( ) code

1/14/2013 CompSci101 Peter Lorensen 2

Functions( ) Variables Datastructures Control structures Functions( ) Variable Type Value Datastructures (String) List Set Tuple Dictionary Control structures If For loop While loop (Exceptions)

slide-3
SLIDE 3

Objects – a teaser

1/14/2013 CompSci101 Peter Lorensen 3

def load_lines(filename): lines = [] f = open(filename) for line in f.readlines(): line = line.strip() lines.append(line) return lines

file.read([size]) Read at most size bytes from the file (less if… file.readlines([sizehint]) Read until EOF using readline() and return a list… file.seek(offset[, whence]) Set the file’s current position, like stdio‘s fseek()… file.write(str) Write a string to the file. There is no return… ......... ........

File Object

slide-4
SLIDE 4

Shafi Goldwasser

  • RCS professor of computer science at

MIT – Twice Godel Prize winner – Grace Murray Hopper Award – National Academy – Co-inventor of zero-knowledge proof protocols How do you convince someone that you know [a secret] without revealing the knowledge?

  • Honesty and Privacy

1/14/2013 CompSci101 Peter Lorensen 4

Work on what you like, what feels right, I now of no

  • ther way to end up

doing creative

slide-5
SLIDE 5

Turing Award

  • Given by the Association

for Computing Machinery (ACM)

1/14/2013 CompSci101 Peter Lorensen 5

  • Given to "an individual selected for contributions of a

technical nature made to the computing community".

  • "The contributions should be of lasting and major

technical importance to the computer field“.

  • The Turing Award is recognized as the "highest

distinction in Computer science“ and "Nobel Prize of computing".

slide-6
SLIDE 6

Silvio Micali

  • Professor of computer science at MIT

– Godel Prize winner – Fellow of the IACR – Co-inventor of zero-knowledge proof protocols How do you convince someone that you know [a secret] without revealing the knowledge?

1/14/2013 CompSci101 Peter Lorensen 6

slide-7
SLIDE 7

Tuples

tup[1] = 8

1/14/2013 CompSci101 Peter Lorensen 7

  • Tuple is like a list
  • Immutable: you can not change it.

grades = “A”, “B”, “C”, “D” You can just write elements in the tuples like this..... tub = ( 1, 2, 3 ) ..but we often put ( ) around them to signal that its a tuple Immutable: Will give an error!

slide-8
SLIDE 8

APT MemberShip

1/14/2013 CompSci101 Peter Lorensen 8

def whosDishonest(club1, club2, club3): guilty = set() # Empty set """ Making a list of clubs converted to sets""" allClubs = [ set(club1), set(club2), set(club3)] for redIndx in range( len( allClubs) ): for greenIndx in range(redIndx, len( allClubs)): common = allClubs[redIndx] & allClubs[greenIndx] guilty = guilty.union( common ) for redIndx in range( len( allClubs) ): for greenIndx in range(redIndx+1, len( allClubs)): common = allClubs[redIndx] & allClubs[greenIndx] guilty = guilty.union( common ) for redIndx in range( len( allClubs) ): for greenIndx in range(redIndx, len( allClubs)-1): common = allClubs[redIndx] & allClubs[greenIndx] guilty = guilty.union( common ) result = list( guilty ) # Converting to list result.sort() # Sorting return result

A B C

slide-9
SLIDE 9

1/14/2013 CompSci101 Peter Lorensen 9

APT FriendScore

slide-10
SLIDE 10

APT FriendScore pseudocode

2-friends consist of to counts: 1) all your friends (called immediate friends) 2) all of your friends friends, BUT you can NOT count someone twice! Run through all people and for each of them do the following:

a) count the number of their immediate friends. b) for each immediate friend, count his friends. a and b are added. The result is compared to the previous highest found value and if higher then replaces it. The final high score is returned.

1/14/2013 CompSci101 Peter Lorensen 10