L a b  /  H o m e w o r k A s s i g n m e n t s

Introduction to Computer Science - Term 2

Brown Mykolyk

Spring 2015


Unless otherwise specified, each submission should have a heading in this format:

 <Firstname> <Lastname>

 IntroCS2 pd<p>

 HW<n> -- <Title/Topic/Summary>

 <yyyy>-<mm>-<dd>   


HW #62: Thou Shalt Not Crash

Due M 2015-06-15, 8:00am, EST.

Make sure your latest working version of your final project loads at this URL:

http://lisa.stuy.edu/~user/proj/ 

When your project is ready to be assessed, reply-all to your proposal thread:

HW #61: Status Report Deux

Due F 2015-06-12, 11:59pm, EST.

The other team member: Reply-all to your team’s project proposal email thread (If it took you multiple tries, use the one that finally worked -- the one to which I replied with green/yellow/red status.) In your email, summarize the current state of your project and progress made since your last status report, addressing these points at minimum:

HW #60: Status Report

Due R 2015-06-11, 8:00am, EST.

One team member: Reply-all to your team’s project proposal email thread (If it took you multiple tries, use the one that finally worked -- the one to which I replied with green/yellow/red status.) In your email, summarize the current state of your project and progress made thus far, addressing these points at minimum:

HW #59: Formal Textification

Due R 2015-05-28, 8:00am, EST.

1. If you have a koding.com account, invite a classmate. If you do not have an account, seek an invite and use it to create an account. Use koding.com as your development platform for this assignment, which will eventually live on Lisa.

2. Write and publish an HTML front-end display page (textForm.html) and a Python back-end script (textForm.py) that will allow a user to enter text and see the text re-displayed according to the user input given. Front page should have

The radio buttons will allow a user to select one of two options: “ROT13” or “Reverse.” The check boxes will allow a user to select any combination of bold, italics, and underline. After clicking your submit button, the user should see their input ROT13-ified or reversed, as well as boldfaced/italicized/underlined as appropriate.

3. Robustify. Note robustifications in block comment at top of Python file.

4. Embellish as you like. Note embellishments in block comment at top of source file.

General guidelines:

...

   |

___hw_________

|             |

...      _____59________

         |              |

     textForm.html       textForm.py

HW #58: Going Formal

Due W 2015-05-27, 8:00am, EST.

Write and publish an HTML front-end display page (triForm.html) and a Python back-end script (triForm.py) that will process the form data generated by the front-end to generate an HTML page showing a visitor the perimeter and area of a triangle with side lengths a, b, c. Front page should have a text input form element for each side length, as well as a submit button.

General guidelines:

...

   |

___hw_________

|             |

...      _____58________

         |              |

    triForm.html    triForm.py

HW #57: Clever Genii, Inc.

Due F 2015-05-22, 8:00am, EST.

1. Write and publish a Python script (triCGI.py) that will generate an HTML page showing a visitor the perimeter and area of a triangle with side lengths a, b, c --- assuming a QUERY_STRING value like a=3&b=4&c=5. Instead of manually parsing the query string, this script will use cgi.FieldStorage().

General guidelines:

...

   |

___hw___

|       |

...     57

        |          

       triCGI.py        

HW #56: GET Some Computation Done

Due R 2015-05-21, 8:00am, EST.

1. Write and publish a Python script (tri.py) that will generate an HTML page showing a visitor the perimeter and area of a triangle with side lengths a, b, c --- assuming a QUERY_STRING value like a=3&b=4&c=5.

General guidelines:

...

   |

___hw___

|       |

...     56

        |          

       tri.py        

HW #55: GET Started Simply

Due W 2015-05-20, 8:00am, EST.

1. Write and publish a Python script (echoGet.py) that will generate an HTML page showing a visitor the query string passed via the URL using the HTTP GET request method.

E.g.,

for

http://lisa.stuy.edu/~user/hw/55/echoGet.py

the page would simply state that there was no query string.

However, for

http://lisa.stuy.edu/~user/hw/55/echoGet.py/?q=foo

or

http://lisa.stuy.edu/~user/hw/55/echoGet.py/?q=foo&wha=hoo

the page would show simply

q=foo

or

q=foo&wha=hoo

...respectively.

General guidelines:

...

   |

___hw___

|       |

...     55

        |          

     echoGet.py         

HW #54: Better Code Through Incremental Revision

Due T 2015-05-19, 8:00am, EST.

As a duo, review and update/refactor your prior HW’s Python script. You are encouraged to seek the eyes and brains of neighbouring teams to this end.

General guidelines:

...

   |

___hw_________

|             |

...      _____54_________________________________

         |           |            |              |

     data01.csv   data02.csv    analyze.py    analysis.html

HW #53: Present Your Findings

Due M 2015-05-18, 8:00am, EST.

As a duo, write a Python script to read at least two CSV files and write an HTML file which will display their contents in a manner clearly illustrating an interesting trend or correlation you have discovered. Your HTML page should contain a mixture of explanatory text and tables to convey your interesting findings. Cite sources for your raw data and provide links to the data files (see partial tree below).

General guidelines:

...

   |

___hw_________

|             |

...      _____53_________________________________

         |           |            |              |

     data01.csv   data02.csv    analyze.py    analysis.html

HW #52: Correlation Is Not Causation_

Due F 2015-05-15, 8:00am, EST.

1. As a duo, find an interesting dataset containing NYCDOE school codes and develop a plan for establishing a correlation between its data and your SAT data.

2. In a plaintext document, document your progress thus far and optionally state the beginnings of your plan for analysis.

General guidelines:

'''

'''

HW #51: How Many Numbers Could a Thinker Crunch, if a Thinker Could Crunch Numbers?

Due R 2015-05-14, 8:00am, EST.

Write a Python script (genTableSAT.py) that will read a CSV file (data_SAT2014.csv) in the same directory and use its contents to generate an HTML file (statsSAT.html). When rendered in a browser, this HMTL file will yield

  1. a brief explanatory paragraph for the viewer
  2. basic statistical information (mean, median, mode, hi, lo, etc… )
  3. a table containing the data in the CSV file

General guidelines:

HW #50: Crunching Real Numbers  

Due W 2015-05-13, 8:00am, EST.

Write a Python script (genTableSAT.py) that will read a CSV file (data_SAT2014.csv) in the same directory and use its contents to generate an HTML file (statsSAT.html). When rendered in a browser, this HMTL file will yield

  1. a brief explanatory paragraph for the viewer
  2. basic statistical information (mean, median, mode, hi, lo, etc… )
  3. a table containing the data in the CSV file

General guidelines:

HW #49: CSV -> HTML

Due T 2015-05-12, 8:00am, EST.

Write a Python script (genTable.py) that will read a CSV file (testdata.csv) in the same directory and use its contents to generate an HTML file (table.html). When rendered in a browser, this HMTL file will yield a table containing the data in the CSV file.

General guidelines:

HW #48: Text Analysis, Webified

Due F 2015-05-08, 8:00am, EST.

1. Download the plaintext version of your favorite work from www.gutenberg.org. Save locally as lit.txt.

2. Write a Python script (wordtally.py) to parse your chosen literary work and tally frequencies of each word. Include a block comment at the top of your file summarizing your tallying approach.

3. Incorporate your code from wordtally.py into an HTML-generating script, to create a new page on your website (see partial filesystem tree below). This page will display a table of the 30 most frequently occurring words in your chosen work, along with an appropriate title/heading, explanatory text, and a hyperlink to lit.txt. Your table should have two columns: words on the left, corresponding frequencies on the right.

4. Upload wordtally.py to the homework server, observing usual guidelines.

...

   |

___hw___

|       |

...     48________

        |         |

     top30.py    lit.txt

HW #47: Log: Better Than Bad, It’s Good!

Due R 2015-05-07, 8:00am, EST.

Upload to the HW server your plaintext development log chronicling progress made on your text analysis project. Include brief (1-3 sentence) explanation of why you chose to do these steps first, as well as your new and improved plan.

HW #46: What’s the FrequencyPlan, Kenneth?_

Due W 2015-05-06, 8:00am, EST.

  1. As a duo, develop a plan for tallying frequencies of each word in a novel (or equivalently lengthy work).
  2. Transcribe into a plaintext document to lay groundwork for implementation.

General guidelines:

'''

CORE ALGO for Word Frequency Tallying

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. books break

2. the shackles of time

3. proof that

4. humans can work magic

5. -Carl Sagan

Exceptional Cases, etc. (to be addressed after core established)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. dis

2. dat

3. dee uddating

'''

HW #45: Four de Toid Thyme

Due T 2015-05-05, 8:00am, EST.

Use pair programming to implement the Python functions below. Include given test cases as well as any extras you wish to generate.

General guidelines:

1. modeLB(nums) returns the mode of the set of numeric elements in list nums. Uses a dictionary to implement the “labeled buckets” algorithm.

modeLB( [0,5,7,3,2,3] ) → 3

modeLB( [0,5,7,3,7,3] ) → 3  ( or 7 )  #handle this as best you see fit

HW #44: Better Templates Through Crowdsourcing

Due F 2015-05-01, 8:00am, EST.

  1. Post your template for an HTML-generating Python script to piazza.
  2. Peruse templates posted by others.
  3. Pick your favorite.
  4. Make it your own. (As always, giving credit where due.)
  5. Upload/copy your new templateHTML.py to your home directory on Lisa.

HW #43: ASCIIng About Your Visage_

Due R 2015-04-30, 8:00am, EST.

Part A: Implement the Python functions below as a dynamic duo. Include given test cases as well as any extras you wish to generate.

General guidelines:

1. common(L1,L2) takes 2 lists as input and returns a new list containing values common to both. Assumes no repeated values in either list.

e.g.,

common( [1,5,4,3,2] , [4,5,10,15] ) → [4,5]

2. alphabetize(names) takes a string of names, assumed to be in Last-First pairings, separated by commas, and returns an alphabetized list of names with line breaks in string form. Summarize algorithm in a block comment preceding your function.

e.g.,

alphabetize( “Wayne,Bruce,Kent,Clark,Parker,Peter” ) → “Kent Clark\nParker Peter\nWayne Bruce”

Part B: Publish your face generator to your website. Each page refresh should yield a randomly-generated ASCII face. Add to your website on Lisa as shown in the subtree below.

...

   |

___hw___

|       |

...     43

        |

     face.py

HW #42: Vroom Vrooom WOW!

Due W 2015-04-29, 8:00am, EST.

Publish your madlibifier to your website. Each page refresh should yield a newly-madlified story, using HTML to format.

General guidelines:

...

   |

___hw___

|       |

...     42

        |

     madlibify.py

HW #41: Vroom Vrooom...

Due T 2015-04-28, 8:00am, EST.

Publish your madlibifier to your website. Each page refresh should yield a new madlification of your team’s story, as plaintext.

General guidelines:

...

   |

___hw___

|       |

...     41

        |

     madlibify.py

HW #40: Tune Your Engine

Due M 2015-04-27, 8:00am, EST.

As a duo, implement your plan for simple madlibification by writing the function below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

'''

Mechanism for Madlibification

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

blah blah

blah

yakkity smakkity

New Features in Version 2:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. wha

2. hoo

3. hah...

'''

1. madlibify(story) takes a string containing placeholders (<NOUN>, <VERB>, ...and whatever other placeholders you devise) and returns a string where all placeholders have been replaced with a random string from the appropriate list of strings. (E.g., <CITY> would be replaced with a random element from the list cities ( [“Paris”, “Milan”, “Quahog”, ...] ). Relies on a global list variable for each placeholder type, and a global string variable for each story to be madlibified.

e.g.,

myStory1 = “The <ADJECTIVE> <NOUN-SINGULAR> <VERB-PAST-SINGULAR> <ADVERB> upside down.”

madlibify(myStory1) → “The clever student walked slowly upside down.”

HW #39: Put Your Plan Into Action

Due F 2015-04-24, 8:00am, EST.

As a duo, implement your plan for simple madlibification by writing the function below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. fillBlanks(story) takes a string containing placeholders of the form <NOUN>, <VERB>, etc. and returns a string where all placeholders have been replaced with a random string from the appropriate list of strings. (E.g., An occurrence of <NOUN> would be replaced with an element of [“dog”, “cat”, “truck”], selected at random.) Uses global variables nouns, verbs, adjs, advs.

e.g.,

fillBlanks(“The <ADJECTIVE> <NOUN> <VERB> <ADVERB> upside down.”) → “The clever student walked slowly upside down.”

Note: Include your block comment algo summary at top of file.

HW #38: Best Laid Plans...

Due R 2015-04-23, 8:00am, EST.

As a duo, develop a plan for madlibification. Then transcribe into a plaintext document to lay the groundwork for implementation.

General guidelines:

'''

Mechanism for Madlibification

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

blah blah

blah

yakkity smakkity

'''

HW #37: Oh, Give Me a Home Where the Buffalo Roam

Due W 2015-04-22, 8:00am, EST.

Implement the Python functions below. Include given test cases, as well as any extras you wish to generate.

General guidelines:

1. merge(L1,L2) Returns a new list containing the elements of both lists, in sorted (ascending) order. Assumes each input list is sorted. (Therefore, you may not use any sorting functions as helpers.) The length of the output list should equal the sum of the lengths of the input lists.

e.g.,

a = [0, 2, 4, 6, 8]

b = [1, 3, 5, 7]

merge(a,b) → [0, 1, 2, 3, 4, 5, 6, 7, 8]

2. randList(n) Returns a list with n elements where each element is a randomly generated number (from any range of values you like).

e.g.,

randList(3) → [?,?,?]

3. randIP() Returns a string representing a randomly generated IP address.

e.g.,

randIP() → ?

HW #36: Bucket List

Due T 2015-04-21, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. modeList(nums) returns the mode, as a single number, of the set of numeric elements in list nums. Uses the “labeled buckets” algorithm discussed in class.

modeList( [0,5,7,3,2,3] ) → 3

modeList( [0,5,7,3,7,3] ) → 3  ( or 7 )

2. vBarGraphify(nums) takes a list of non-negative integers and prints a set of vertical bars.

>>> x = [0,1,2,3]

[0, 1, 2, 3]

>>> vBarGraphify(x)

      *

    * *

  * * *

0 1 2 3

>>> x = [1,0,3,2]

[1, 0, 3, 2]

>>> vBarGraphify(x)

    *  

    * *

*   * *

0 1 2 3

HW #35: Stats on Stats on Stats

Due M 2015-04-20, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1a. modeListA(nums) returns the mode, as a single number, of the set of numeric elements in list nums.

modeListA( [0,5,7,3,2,3] ) → 3

modeListA( [0,5,7,3,7,3] ) → 3  ( or 7; either could be acceptable )

1b. modeListB(nums) returns the mode, as a list, of the set of numeric elements in list nums.

modeListB( [0,5,7,3,2,3] ) → [3]

modeListB( [0,5,7,3,7,3] ) → [3,7]

2. vBarGraphify(nums) takes a list of non-negative integers and prints a set of vertical bars.

>>> x = [0,1,2,3]

[0, 1, 2, 3]

>>> vBarGraphify(x)

      *

    * *

  * * *

0 1 2 3

>>> x = [1,0,3,2]

[1, 0, 3, 2]

>>> vBarGraphify(x)

    *  

    * *

*   * *

0 1 2 3

HW #34: Stat-tastic

Due F 2015-04-17, 8:00am, EST.

Implement the Python functions below. Generate appropriate test cases to verify functionality.

General guidelines:

1. meanList(nums) returns the arithmetic mean of the numeric elements in list nums.

2. medList(nums) returns the median of the numeric elements in list nums.

                    Challenge: Write medList() without using the Python function sorted().   

3. barGraphify(nums) takes a list of non-negative integers and prints a horizontal bar for each index, commensurate with the value at said index. Exempli gratia,

>>> x = [0,1,2,3]

[0, 1, 2, 3]

>>> barGraphify(x)

0:

1: =

2: ==

3: ===

>>> x = [1,0,3,2]

[1, 0, 3, 2]

>>> barGraphify(x)

0: =

1:

2: ===

3: ==

HW #33: Removal Three Ways

Due R 2015-04-16, 8:00am, EST.

As a duo, rewrite rmNegatives(L) using the the built-in Python tools pop(), remove(), or del.

General guidelines:

“””

POP:

syntax:

behavior:

REMOVE:

syntax:

behavior:

DEL:

syntax:

behavior:

<TeamName> prefers <chosen lib fxn> for use in rmNegatives() because...

“””

HW #32: Come Together

Due W 2015-04-15, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

Include a block comment under heading in this format:

# 1. WvF: <Justification for using WHILE or FOR loop for function 1>

# 2. WvF: <Justification for using WHILE or FOR loop for function 2>

# 3. WvF: <Justification for using WHILE or FOR loop for function 3>

1. rmNegatives(L) removes the negative numbers from list L, assumed to contain only numeric elements. (Modifies L; does not create

a new list.)

rmNegatives( [5,4,3,2,1] ) → [5,4,3,2,1]

rmNegatives( [5,-4,3,-2,1] ) → [5,3,1]

2. listFib(n) returns a list of the first n Fibonacci numbers, starting with 0 as the 0th term, 1 as the 1st term, 1 as the 2nd term, and so on.

listFib(1) → [0]

listFib(2) → [0,1]

listFib(3) → [0,1,1]

listFib(4) → [0,1,1,2]

3. sentify(L) returns a string comprised of list L’s elements, in order, with spaces between. Assumes L contains only string elements.

sentify( [“this”, “is”, “how”, “we”, “do”] ) → “this is how we do”

HW #31: Back in the [Co]Driver’s Seat, Looping_FTW

Due T 2015-04-14, 8:00am, EST.

Implement each Python function below using a FOR loop. Include given test cases, as well as any helpful extras.  

Note: min(), max(), index(), find() primitives disallowed.

General guidelines:

1. listSum(L) takes a list L containing only numbers, and returns the sum of L’s elements.

listSum( [0,1,2,3] ) → 6

2. minVal(L) takes a list L containing only numeric elements, and returns the least value.

e.g.,

minVal( [3] ) → 3

minVal( [5,4,3,2,1] ) → 1

3. listFind(L,q) takes a list L and a query q as inputs, and returns the first index where q occurs in the L. Returns -1 if q is not found in L.

listFind([5,4,3,2,1], 2) → 3

listFind([5,4,3,2,1], 6) → -1

listFind([5,4,’cat’,’dog’,’cat’], ‘cat’) → 2

4. minPos(L) takes a list L containing only numeric elements, and returns the position (index) of the least value.

e.g.,

minPos( [3] ) → 0

minPos( [5,4,3,2,1] ) → 4

HW #30: Float Like a Butterfly, Sting Like a Bee_

Due W 2015-04-01, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. minPos(L) takes a list L containing only numeric elements, and returns the position (index) of the least value.

e.g.,

minPos( [3] ) → 0

minPos( [5,4,3,2,1] ) → 4

HW #29: ...and Now For Something Completely Different_

Due T 2015-03-31, 8:00am, EST.

1. Upload to the HW server your Gold, Silver and Bronze medal-winning teams. Observe format shown.

Gold: Team ____ because ...

Silver: Team ____ because ...

Bronze: Team ____ because ...

2. Implement Python functions to solve the List-1 CodingBat exercises.

Do as many as you can, but make sure you understand

Suggested workflow: Compose in IDLE, copy/paste into CodingBat.

HW #28: Ealizeray Ouryay Isionvay  

Due M 2015-03-30, 8:00am, EST.

Implement a translation engine capable of converting an English phrase as shown below to its Pig Latin equivalent.

First, review your team’s plan to make sure each of you understands it and possibly make adjustments.

General guidelines:

1. translate(phrase) returns Pig Latin equivalent of the string phrase.

e.g.,

translate(“What are the rules of Pig Latin?”) → “Atwhay areway ethay ulesray ofway Igpay Atinlay?”

translate(“the pope rocks red kicks”) → “ethay opepay ocksray edray ickskay”

PROTIP: Write a preliminary version of translate that implements the basic Pig Latin rule, but does not handle any exceptional cases. Incrementally augment it, testing with each addition, as you move down your precedence-ordered list of rules. Each time you reach a milestone, save your work to a backup file.

LULZTIP: Find a story of appreciable length that all teammates dig. Incorporate as a test input.

HW #27: Anslatingtray Englishway intoway Igpay Atinlay  

Due F 2015-03-27, 8:00am, EST.

Design a translation engine capable of converting an English phrase as shown below to its Pig Latin equivalent. Your goal by Monday (3/30) will be to have a working translate() function.

First, design a plan, starting with the simplest possible rule system. Then incrementally modify your functions, add helper functions, etc, ...until you eventually end up with the translate() function below.

General guidelines:

'''

PIG LATIN RULES:

1. blah blah blah

2. yadda yadda yadda

3. oink oink oink

4. etc... (List rules in order of precedence.)

OUTLINE:

<Concise summary of your approach, including mention of how your functions work together.>

DEVELOPMENT PLAN:

<Roughly, an ordered to-do list.

Guidelines:

What is the simplest function you can write and test first?

Slightly modified version that you will test next?

Next function you will develop?

Etc…>

DEVELOPMENT LOG:

yyyy-mm-dd <time>

<thinker(s) to whom credit is due>: Task accomplished (or attempted)...

etc.

'''

1. translate(phrase) returns Pig Latin equivalent of the string phrase.

e.g.,

translate(“What are the rules of Pig Latin?”) → “Atwhay areway ethay ulesray ofway Igpay Atinlay?”

translate(“the pope rocks red kicks”) → “ethay opepay ocksray edray ickskay”

HW #26: Further Explorations in Toy_Encryption

Due R 2015-03-26, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

4. rot13(phrase) takes a string input -- potentially including spaces, punctuation and a mixture of upper- and lowercase letters -- and returns its rot13 encoding.

e.g.,

rot13(“Justin Bieber”) → “Whfgva Ovrore”

rot13(“Justin Bieber? Like, OMG!!! He's my hero!”) → “Whfgva Ovrore? Yvxr, BZT!!! Ur'f zl ureb!”

5. Using tools introduced thus far in class, implement a Python function (or a few) to tackle the task below.
   Summarize your approach in a block comment at the top of your .PY file.

The Challenge:

Below are 3 words, each encoded in a style similar to rot13, except that the letters are not shifted by 13, but instead some other number. (For example, it could be rot2, where "a" maps to "c" and "z" maps to "b"). Try to decode these strings. How many letters are they shifted by?

deoh

ufwyd

udm

.

.

.

Cppkg ctg aqw QM?

Abzqdqvo nwz xmznmkbqwv mdmz aqvkm Q eia i avwbvwam

Apnly nva av obua, ipyk nva av msf; Thu nva av zpa huk dvukly, 'Dof, dof, dof?' Apnly nva av zsllw, ipyk nva av shuk; Thu nva av alss optzlsm ol buklyzahuk.

Roi roi! Ry ry! Cyzr-Pbycr CSXQ! tecd cdyvo dro cryg!

HW #25: Cereal-Grade Encryption

Due W 2015-03-25, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. rot13Chr(ch) takes a single-letter string input and returns its rot13 equivalent.

e.g.,

rot13Chr(‘B’) → ‘O’

rot13Chr(‘b’) → ‘o’

2. printEmAll() prints all letters of the alphabet along with the rot13 equivalent of each.

e.g.,

printEmAll() →

A <-> N

B <-> O

...

a <-> n

b <-> o

...and so on

3. rot13Wrd(word) takes a string input (all caps, no spaces) and returns its rot13 encoding.

e.g.,

rot13Wrd(“JABBERWOCKY”) → “WNOOREJBPXL”

HW #24: Reaching Out to the Neighbors

Due T 2015-03-24, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. closerNum(target,num1,num2) operates on 3 numeric parameters, returning a string stating which of the 2nd and 3rd arguments is closer to the first.

e.g.,

closerNum(8,20,10) → “8 is closer to 10”

closerNum(8,20,2) → “8 is closer to 2”

closerNum(8,-2,30) → “8 is closer to -2”

HW #23: Hone Your Skills

Due M 2015-03-23, 8:00am, EST.

With your trio, implement Python functions to solve these CodingBat exercises. Suggested workflow: Compose in IDLE, copy/paste into CodingBat.

HW #22: Slice, Dice, Replace

Due F 2015-03-20, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. tablefyASCII() returns a string of valid HTML code which will generate a 2-column, 53-row table. Each non-heading row will show a letter of the alphabet and its corresponding ASCII value. Letters on the left, numbers on the right.

2. replace(s,q,r) takes 3 string inputs and replaces any occurrences of q in s with r. If there is no occurrence of q in s, then s is returned unchanged.

e.g.,

replace(“Winter is coming”, “Winter”, “Spring”) → “Spring is coming”

replace(“Dolphins run this planet”, “dolphins”, “mice”) → “Dolphins run this planet”

HW #21: 000 000 111, v10

Due R 2015-03-19, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. bondify(name) takes a name written in First Last format, and returns the sassy version, as shown below.

bondify(“James Bond”) → “Bond, James Bond”

HW #20: 000 000 111

Due W 2015-03-18, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. bondify(name) takes a name written in First Last format, and returns the sassy version, as shown below.

bondify(“James Bond”) → “Bond, James Bond”

HW #19: Stringy Loops

Due T 2015-03-17, 8:00am, EST.

Implement the Python functions below. Include the given test cases, as well as any extras you wish to generate.

General guidelines:

1. addMultPrint(a,b) takes 2 numeric inputs and prints a message like that shown below.

addMultPrint(3,6) →

“the sum of 3 and 6 is 9

their product is 18”

2. addMultHTML(a,b) takes 2 numeric inputs and returns a string of HTML code that will render as shown below.

addMultHTML(3,6) →

the sum of 3 and 6 is 9 

their product is 18

3. tablefy(n) takes a positive integer input and returns a string of HTML code that will render a table like the one below.

tablefy(10) →

HW #18: Loopy

Due M 2015-03-16, 8:00am, EST.

As a trio, implement the Python functions below using WHILE loops.

Workflow:

1. Read.

2. Discuss with your trio to make sure you understand the problem.

3. Bounce ideas off of one another regarding an algorithm to solve said problem.

4. Sketch out algorithm(s) using pseudocode and/or flowcharts.

5. Generate a set of test cases and expected outputs -- starting with trivial ones and moving up to more interesting ones.

6. Implement (write Python code).

7. Test as you develop. (Comment out all but the simplest test cases. Uncomment one test call at a time…)

General guidelines:

1. sumDigits(n) takes a positive integer n and returns the sum of its digits.

2. squares(n) takes a positive integer n and prints each integer from 1 to n, inclusive, along with its square. The number and its square should appear on the same line.

3. sumPerfSqs(n) takes a positive integer n and returns the sum of the perfect squares between 1 and n, inclusive.

HW #17: Repetition, Two Ways

Due F 2015-03-12, 8:00am, EST.

Implement the Python functions below.

General guidelines:

1. factR(n) uses recursion to calculate and return n!.

e.g.,

factR(0) → 1

factR(1) → 1

factR(2) → 2

factR(3) → 6

factR(4) → 24

2. factW(n) uses iteration (in the form of a WHILE loop) to calculate and return n!.

e.g.,

factW(0) → 1

factW(1) → 1

factW(2) → 2

factW(3) → 6

factW(4) → 24

HW #16: Reflection with Intent to Improve

Due R 2015-03-12, 8:00am, EST.

In a plaintext file, compose 2 paragraphs: one explaining what went wrong (and right) on exam day, and one explaining how you will alter your approach next time.

HW #15: The Handoff

Due W 2015-03-11, 8:00am, EST.

Work through these CodingBat exercises. Suggested workflow: Compose in IDLE, copy/paste into CodingBat.

Implement the Python functions below.

General guidelines:

1. numRealRoots(a,b,c) takes numeric inputs a, b, c -- representing coefficients of a quadratic equation in standard form -- and returns the number of real roots of said equation.
e.g.,

numRealRoots(1,2,3) → 0

numRealRoots(2 4 2) → 1

numRealRoots(1,3,2) → 2

2. quadSolver(a,b,c) takes numeric inputs a, b, c -- representing coefficients of a quadratic equation in standard form -- and prints the roots, if any. Uses numRealRoots(a,b,c) as a helper function.
e.g.,

quadSolver(1,2,3) → “no real roots”

quadSolver(1,4,4) → -2

quadSolver(1,-2,-15) → -3  5

HW #14: Letters & Numbers

Due T 2015-03-10, 8:00am, EST.

Implement the Python functions below.

General guidelines:

1. gradeConv(g) takes a numeric input g, representing a student’s grade, and returns its letter grade equivalent, according to this breakdown:

A: 90-100
B: 80-89

C: 70-79
D: 65-69

F: 0-64

e.g.,

< Generate your own test cases. Pay close attention to border cases... >

2. passJudgement(letterGrade) takes a string input letterGrade and prints congratulatory or scolding messages.

HW #13: [Perfect] Practice Makes Perfect

Due R 2015-03-05, 8:00am, EST.

1. Create an account at CodingBat using the same email address you use for this class.

2. Navigate to the preferences section of CodingBat (once logged in, look in upper right for “prefs” link).

3. Enter your last name and preferred first name.

4. In the “Share to” field, enter your instructor’s email address.

5. Make sure you have clicked the appropriate button to save your changes in each section.

Workflow tip: You may find it helpful to compose your code in IDLE, testing using its shell, before copying and pasting into CodingBat’s text field.

HW #12: Boolean Logic, Conditionals, Oh My!

Due R 2015-03-05, 8:00am, EST.

Implement the Python functions below.

General guidelines:

1. cartDist(X1,Y1,X2,Y2) takes numeric inputs X1, Y1, X2, Y2 -- representing coordinate pairs (x1,y1) and (x2,y2) -- and returns the distance between the two points.
e.g.,

cartDist(0,0,0,0) → 0

cartDist(4,4,4,4) → 0

cartDist(0,0,3,4) → 5

2. pythTriple(a,b,c) takes numeric inputs a, b, c -- representing side lengths of a triangle -- and returns a boolean value to indicate whether the they constitute a Pythagorean triple.

e.g.,

pythTriple(0,0,0) → False

pythTriple(3,4,5) → True

pythTriple(3,4,6) → False

pythTriple(32,255,257) → True

(Hint: What other representative test cases are glaringly omitted here?)

HW #11: Visiting Old Friends

Due W 2015-03-04, 8:00am, EST.

Define the Python functions below.

Write expected outputs into your code as comments, so that you have a reference for your test cases.

i.e., #...should be 3.14159265359

1. areaCirc(r) takes numeric input r and returns the area of a circle of radius r.
e.g.,

areaCirc(1) → 3.14159265359

areaCirc(3) → 28.2743338823

areaCirc(5) → 78.5398163397

2. areaWasher(radInner,radOuter) takes numeric inputs radOuter, radInner and returns the area of a washer with inner radius radInner and outer radius radOuter.
e.g.,

areaWasher(0,2) → 12.5663706144

areaWasher(3,5) → 50.2654824574

areaWasher(6,10) → 201.06192983

3. sumOfSquares(a,b) takes numeric inputs a, b and returns the sum of their squares.
e.g.,

sumOfSquares(0,0) → 0

sumOfSquares(1,2) → 5

sumOfSquares(4,5) → 41

General guidelines:

HW #10: Name Your Creations

Due T 2015-03-03, 8:00am, EST.

  1. Translate the expressions below into Python code.
  2. Once you have verified that your grammar is correct, assign each expression to a cleverly chosen variable name, in a plaintext file named expressions01.py. (Note: This is entirely doable with the Python you know thus far.)
  3. Upload this file to the homework server.

                          

a.      

b.      

c.      

HW #09: Break It Down, Build It Up

Due R 2015-02-26, 8:00am, EST.

Bring your Lisa-hosted web presence into alignment with the file tree shown below.

homedir______________________

                             |

                  _______public_html______________

                 |                                |

                 |                              index.html

      __________hw_____________________________________________________            

     |                              |                                  |

     09              _______________06________________                 08

     |              |       |             |           |                |

  index.html       img    subdir    index.html    page01.html       index.html

                            |

                          page02.html

HW #08: Imitation Game

Due W 2015-02-25, 8:00am, EST.

  1. Open http://lisa.stuy.edu/~tofr/clonethis.gif in its own browser window.
  2. Open http://lisa.stuy.edu/~username/mimic.html in its own browser window.
    (This will not load, since you have not created it yet. You are simply preparing a test window for refreshing as you develop.)
  3. Open a terminal session, a file browser, and your favorite text editor.
  4. Write HTML code in mimic.html, located as shown below, to mimic the observed design.

homedir______________________

                             |

                   ________public_html______________

                  |                                 |

  _______________site_______________             mimic.html

 |       |             |            |

img    subdir      index.html     page01.html

         |

       page02.html

HW #07: What Can Your Little Friend Do For You?

Due T 2015-02-24, 8:00am, EST.

  1. Read this and this.
  2. In a plaintext file, compose a haiku expressing your thoughts on the matter.
  3. Upload to the HW server

HW #06: Porta-Site

Due F 2015-02-13, 8:00am, EST.

1. Re-create on your home machine the site generated today in class.

Goal: After loading any of the 3 pages in a web browser, you should be able to navigate to the other pages and back without clicking the browser’s Back button.

Directories: site, img, subdir

Files: index.html, page01.html, page02.html

 _______________site_______________

 |       |             |           |

img    subdir    index.html    page01.html

         |

       page02.html

2. Compress your site into a ZIP archive. (no RAR)

        a) Navigate to directory above site

        b) Right-click on site, select option to compress into ZIP archive

3. Upload ZIP archive to the homework server.

HW #05: Say Hello To My Little Friend

Due F 2015-02-13, 8:00am, EST.

Bring your duckie with you to class.

HW #04: Sniffing Around the Web

Due W 2015-02-11, 8:00am, EST.

In a new plaintext document, with title/heading “HTML Resources on the Web”, list at least three useful online resources for HTML.

Create an entry in the following format for each of your resources:

<Resource Name>

<Address on the web (URL)>

<How you found this site.>

<Why this site is worth a look.>

HW #03: Muy Importante

Due M 2015-02-09, 8:00am, EST.

HW #02: What Does Your Tree Look Like?

Due F 2015-02-06, 8:00am, EST.

Create a graphical representation of the filesystem hierarchy of your primary computer -- as detailed as you desire, but must feature prominently the path to Documents, Downloads, & Desktop.

heading:


NAME

IntroCS2 pd #

HW##

2015-mm-dd

Filesystem Hierarchy (Directory Tree) for My Machine

hostname: <name of my machine>

OS: <flavor> & <version>


HW #01: Who Are You, and Where Did You Come From?

Due R 2015-02-05, 8:00am, EST.

HW #00: First Things First

Due W 2015-02-04, 8:00am, EST.

Fill out the form here: goo.gl/RcHUoL