Governor's Career & Technical Academy Arlington

CSC 221 Weekly Assignments: Week 11

CSC 221


Overview

This week we will learn to read and write to files using Python.

Thursday, November 9th

Daily PCEP Warm Up

What is the output of the following code?

d = {'zero': 0, 'one': 1, 'three': 3, 'two': 2}
for k in sorted(d.keys()):
    print(d[k], end=' ')

What is the output of the following code?

a, b = 10, 20
print({True: a, False: b}[a < b])

Classwork

Today in class we will get back the last two quizzes we have taken and go over them.

Homework

Complete Lesson 10: Dictionaries from Python for Everybody, including watching the video lectures and completing the end of lesson activities.

Monday, November 6th

Daily PCEP Warm Up

What is the expected output of the following code?

def intro(a="James Bond", b="Bond"):
    print("My name is", b + ".", a + ".")

intro()

How about this one?

def intro(a="James Bond", b="Bond"):
    print("My name is", b + ".", a + ".")

intro(b="Sean Connery")

And this one?

def intro(a, b="Bond"):
    print("My name is", b + ".", a + ".")

intro("Susan")

Classwork

Dr. Chuck shows us the following example to print lines from a file that begin with From::

fhand = open('mbox-short.txt')
for line in fhand:
    line = line.strip()
    if line.startswith('From:'):
        print(line)

Challenge: Replace with four lines of the for with a single line using a list comprehension.

Homework

Start Lesson 10: Dictionaries from Python for Everybody, including watching the video lectures and completing the end of lesson activities.

This assignment will be due before you come to class on Tuesday, November 14th.