CS 683 Emerging Technologies

Fall Semester, 2006

Assignment 1

Assignment Index

© 2006, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 8/28/06

Assignment 1

Due Sept 12

Modified 6-Sep-06. Missing single quote in problem 2 added. Was a[4:2] = ['cat','dog] now is a[4:2]=['cat','dog']

You are to turn in hard copy of your assignment. Please indicate on your paper your status in the course. that is if you are enrolled in the course or are a crasher.

Late homework will be accepted, but with a penalty. An assignment turned in 1-7 days late, will lose 3% of the total value of the assignment per day late. The eight day late the penalty will be 40% of the assignment, the ninth day late the penalty will be 60%, after the ninth day late the penalty will be 90%. Once a solution to an assignment has been posted or discussed in class, the assignment will no longer be accepted. Late penalties are always rounded up to the next integer value.

1. What is the result of executing the following code. Explain why the code does not throw an exception.

a = 'dog'

a[0][0][0]

2. Given the assignment a = [1, 2, 3, 4, 5, 6] what is the slice a[4:2]? What effect does the assignment a[4:2] = ['cat', 'dog'] have?

3. Write a function that returns the sum of the ACII code of each character its string argument.

4. Let the character A have value 1, B have value 2, C have value 3, ... , Z have value 26. The value of a word is the sum of the value of each of its characters. For example the word 'cat' has value 3 + 1 + 20 = 24. A dollar word is a word whose value is 100. Write a function, "dollarWords. The function has one argument, the name of a file. The file contains a list of words separated by spaces. The function returns a list of all dollar words in the file. Use at least one of map, reduce, or filter in your solution.

5. Write unit tests for problem 4.

6. Write a BankAccount class. The class maintains a balance. The balance is initialized to zero when a BankAccount object is created. The class has three public methods: balance, deposit, withdrawal. "balance" returns the balance of the account. "deposit" and "withdrawal" both have one argument. If the argument is not a nonnegative number an exception is to be raised. "deposit" adds its argument to the balance. "withdrawal" subtracts it argument from the balance unless it would make the balance negative. In that case "withdrawal" throws an exception. Write unit tests for the class.

7. Write a function called links. The function has one argument, a url of a web page. The function returns a list of all the links in the give web page. So for example links(' http://www.eli.sdsu.edu ') returns the list:

[' http://www.sci.sdsu.edu/cs/' ,

' http://www.sdsu.edu/map/display.cgi?abbrev=gmcs' , ' mailto:whitney@cs.sdsu.edu ',

' http://www.eli.sdsu.edu:8888/dpsa' , 'blog/index.html', 'courses/index.html',

' http://www.eli.sdsu.edu:8888/sdsmalltalkers' , 'smalltalkcode/index.html',

' http://www.eli.sdsu.edu/java-sdsu/' , 'jobs/jobdata.html', 'forms/',

' http://www.tifaq.com ']

Hint: Links on a web page have the form:

    <a href="theLink">Some text</a>

Use Python's re (regular expressions) module to find in a string all patterns of the form href="aLink" and return the link part of the match.