CS 200 - Fall 2024. 10/28/2024


[Home]

Welcome to CS 200!

Video of the Day

Socratica Python videos:

Bit about Bytes: Understanding Python Bytecode See James BennettWriting more efficient Python code.

I hereby solicit suggestions for the video of the day. Please email me your ideas with explanations. Selected entries will win 5 homework points. If your video is played at the beginning of class, you must also briefly explain something about the video and something about yourself — in person.

Logical problem of the day

x = [True, True, False]
any(x) and not all(x)
What is the output of the above code?

https://pollev.com/slade You may also download the app to your phone. Use the "slade" poll id.

Canvas Quiz of the Day (need daily password)

Most days, there will be a simple canvas quiz related to the lecture. You need a password to activate the quiz, which I will provide in class. These quizzes will count toward your class participation grade. The quiz is available only during class.

Click for today's quiz.

Lecture 16: Computer Architecture and Python Virtual Machine .

Announcements

  • AI Talk today at 4pm, 55 Hillhouse.
    Ignore Previous Instructions: Attacks on AI Systems and What to Do About It. Monday, October 28, 2024 | 4:00pm Horchow Hall, GM Room (55 Hillhouse Avenue)

    The Schmidt Program on Artificial Intelligence, Emerging Technologies, and National Power will host a talk by Ram Shankar Siva Kumar, founder and head of the AI Red Team at Microsoft, which proactively attacks AI systems to identify vulnerabilities. He will provide an overview of the art and science of attacking AI systems and its societal implications.

    Kumar is a leading expert in the intersection of machine learning and security. He is the co-author of the 2023 book, "Not with a Bug, But with a Sticker," and is currently a tech policy fellow at UC Berkeley and an affiliate at Harvard’s Berkman Klein Center. The event is open to the Yale community; registration is required.

  • If you have an upcoming performance or athletic event, I am happy to promote it during class. Just send me a note.

    Administrivia

  • I am available for lunch on Mondays at 1pm (not noon) at Franklin College Dining Hall.

  • I have office hours Wednesdays from 4-6 pm, on zoom, id 459 434 2854.

  • ULA office hours are found at in Ed Discussions.

  • Homework assignments: [Assignments]. hw5 is available.

    hw4: staff solution for myhash had errors:

        def __eq__(self, other):
            if type(other) != type(self):
                return False
            if self.table == other.table:
                return True
            else:
                return False
      
    The eq method compares lists, in which order matters. However, for the hash table buckets, the order does not matter.
    >>> from hw4a import *
    >>> h = myhash(5)
    >>> h.put('a',1)
    >>> h.put('f',2)
    >>> h2 = myhash(5)
    >>> h2.put('f',2)
    >>> h2.put('a',1)
    >>> str(h)
    "myhash([[('a', 1), ('f', 2)], [], [], [], []])"
    >>> str(h2)
    "myhash([[('f', 2), ('a', 1)], [], [], [], []])"
    >>> h == h2
    False
    >>> 
      
    You might want to use flatten as a set comprehsion, so that order does not matter.

    I have fixed the problem in hw4a.pyc. Note that the tables do not need to be the same size.

    >>> from hw4a import *
    >>> h = myhash()
    >>> h.put('a',1)
    >>> h.put('b',2)
    >>> h2 = myhash(5)
    >>> h2.put('b',2)
    >>> h2.put('a',1)
    >>> str(h)
    "myhash([[], [], [], [], [], [], [], [], [], [], [('a', 1)], [('b', 2)], [], [], [], [], [], [], [], []])"
    >>> str(h2)
    "myhash([[('a', 1)], [('b', 2)], [], [], []])"
    >>> h == h2
    True
    

    There is a different problem with the copy method.

        def copy(self):
            h = myhash(self.size)
            h.table = self.table[:]
            h.count = self.count
            return h
      
    This code makes a shallow copy of the list. We need to make a deep copy of the embedded lists. Otherwise, there are problems.
    from hw4a import *
    >>> h = myhash(5)
    >>> h.put('a', 1)
    >>> h2 = h.copy()
    >>> str(h)
    "myhash([[('a', 1)], [], [], [], []])"
    >>> str(h2)
    "myhash([[('a', 1)], [], [], [], []])"
    >>> h.put('b',2)
    >>> str(h)
    "myhash([[('a', 1)], [('b', 2)], [], [], []])"
    >>> str(h2)
    "myhash([[('a', 1)], [('b', 2)], [], [], []])"
      
    The current staff solution, hw4a.pyc, fixes these issues. The previous version is hw4abad.pyc.

    Midterm Exam II: Thursday November 7th, 7pm, ML 211

    The second midterm will similar to the first. You will have 2 hours. Here is a sample midterm exam. (solutions) There will also be a question on data structures.

    There will be a UNIX question, as in the first midterm. Here is a sample UNIX transcript (solutions) UNIX will cover through principle 3.

    Python Virtual Machine

    PVM.html jupyter notebook - Python Virtual Machine and hw5.

    The version of Python on the zoo is 3.10. That is the version used by this assignment and the autograder. There were some major changes to byte codes in version 3.11, and for that matter, in version 3.9. See dis.html and specify version 3.10.

  • bytecode.py
  • pvm.py

  • Recorded lecture 10/26/24 covered Iterators and Decorators:
  • Exceptions.html

    Getting to know UNIX

    UNIX Introduction Principle 3.
    [Home]