Governor's Career & Technical Academy Arlington

CSC 221 Weekly Assignments: Weeks 12 and 13

CSC 221


Overview

Now that we have learned how to use dictionaries, we have only one topic left to have all we need for PCEP certification: exceptions. This week (and next) we will learn about them.

Monday, November 20th

Classwork

Today in class you will have time to finish the mini-project assigned last class.

Homework

Enjoy your time with your family and friends! We'll dive into PCEP prep when we return next week.

Thursday, November 16th

PCEP Practice

  1. What is the output of the following code?

    try:
        n = input("Enter a number: ")
        print(n / n)
    except ValueError:
        print("Bad input...")
    except ZeroDivisionError:
        print("Very bad input...")
    except TypeError:
        print("Very very bad input...")
    except:
        print("Ouch!")
    
  2. What is the output of the following code?

    def f(x):
        return x ** x
    
    def g(x):
        return f(x) * f(x)
    
    print(g(3))
    
  3. Select the true statements about the try-except block in relation to the following example. (Select two answers)

    try:
        # some code is here...
    except:
        # some code is here...
    
    1. The code that follows the try statement will be executed if the code in the except clause runs into an error.
    2. If you suspect that a snippet may raise an exception, you should place it in the try block.
    3. If there is a syntax error in the code located in the try block, the except branch will not handle it, and a SyntaxError exception will be raised instead.
    4. The code that follows the except statement will be executed if the code in the try clause runs into an error.

Classwork / Homework

Today in class we will look at the last topic we need to complete before taking the PCEP: exceptions. After discussing the PCEP practice questions, you will be work with your Python selected partner on a mini-project.

Pairs for Period 4 are:

Grant and Jack
Abi and Toby
Amelie and Alex
Erica and Conrad
Adrian and Noah
Jake and Blu
Evan and Anupama
Alessandra and Keirsten

Pairs for Period 5 are:

Dylan and Fatima
Rockwell and Timothy
Donovan and Udval
Sean and Yuri
Luka and Jonathan
Samuel and Evan
Daniel and Mayah
Colin and Gabriel

Mini-Project: Safely Reading File Data

Working with your partner, do each of the following:

  1. Chose something in the real world about which you want to store data.
  2. Decide on at least three characteristics you want to store.
  3. Represent these characteristics as space separated fields on an line of text.
  4. At least one of these fields should be represented by a string, and another by an integer.
  5. Create a data file with at least 10 of your items, stored one per line.
  6. Using your Python skills, write a program to read in the data from this file, parsing the fields and converting them to their appropriate type.
  7. Be sure to use a try ... except handle any errors that come from trying to open the file and parse the data.

This project is due at the end of class on Monday, November 20th. To earn an A for the project, you should have commits in your git repo reflecting work done during class on Thursday and for homework, as well as during class on Monday if you need time to finish up by then.

Tuesday, November 14th

Classwork

We will start class with a quiz on Lesson 10: Dictionaries from Python for Everybody.

After the quiz, I will check-in with you to confirm that you have access to PCEP prep materials through our CISCO Networking Academy. Yesterday I resent invitations to each of you who had not yet logged into the course. Please check your VCCS email and look for the invitation.

As time permits, I will then begin discussing Chapter 6: Dictionaries, sets, files, and modules with you.

Homework

Spend your homework time becoming familiar with our CISCO Networking Academy PCAP - Programming Essentials in Python online course materials. We are going to begin practicing for the PCEP, so you will want to have this resource available to you.