Solutions can be found here:

Important Notes

All Assignments will be submitted via GitHub classroom. Labs and projects will have their own assignment links, all homeworks should be submitted in the homework repository.

If you did not receive credit (see a 0 on jupiter) for an assignment that you completed, fill out this form. This includes if you submitted work late for an absence or otherwise. _DO NOT__ fill out this form if the assignment doesn’t appear on jupiter at all.


  • Work 35: Test Prep III

    Due: Friday 4/17 10:00 am

    Submission Name: w35_test2.py

    Test Description

    The exam on Friday will focus on the following major topics:

    • split and join
    • dictionaries
    • Using files as data sources
    • Other python topics may also be included.
    • The exam will have multiple choice questions and functions to write. It may have other short-answer type questions as well.
    • You can check out the class slides for review.

    Crowd-Sourced Review

    You can find all the submitted test questions here: https://github.com/mks22-dw/dwsource/tree/main/tests/test02

    Pick 4 of the programming questions to complete. At the beginning of each function you write, include the question number above as a comment. Be sure to include test cases with your program.

    You are encouraged to work on more problems to prepare for the exam. You should also take a look at the multiple choice questions. I have not vetted all the questions, so there may be mistakes.

    Optional Extra Review

    If you want more practice you should check out coding bat. Ignore problems with anything we haven’t covered in class.


  • Work 34: Questioning,Part III

    Due: Thursday 5/16 10:00 am

    Submission Name: t02.py

    Test Description

    The exam on Friday will focus on the following major topics:

    • split and join
    • dictionaries
    • Using files as data sources
    • Other python topics may also be included.
    • The exam will have multiple choice questions and functions to write. It may have other short-answer type questions as well.

    Write Possible Test Questions

    With your TableBuddy™ write two potential test questions.

    1. The first should be a multiple choice questions with 4 options.
    2. The second one should be a function to program.
      • This should be similar to the programming work you have had so far. Include all the information needed to write the function (formulas, etc).

    Put both questions, and the answers in a python file. You are working with your TableBuddy™, but both of you need to submit this file. You can put multiple lines together in a single comment using """ .... """. Use this format:

    """
    MC Question:
    
    Options:
    
    Answer
    
    =======================
    Programming question:
    
    Description
    
    Possible solution:
    =======================
    """
    

    Here is a filled in Example:

    """
    MC Question:
    What is the air speed of an unladen swallow?
    
    Options:
    A) 2 mph
    B) 20 mph
    C) 200 mph
    D) African or European?
    
    Answer: D
    
    =======================
    Programming question:
    
    Write a function that returns the ones
    digit of an integer.
    
    Possible solution:
    =======================
    """
    
    def one_dig(n):
      return n % 10
    

  • Work 33: WHat's Poppin'?

    Due: Thursday 5/16 10:00 am

    Submission Name: w33_csv.py

    On the source code repository you will find a file named cs_lab.py. It is formatted like a lab and contains a number of functions to write that involve working with text, lists and dictionaries. While I am not assigning it as a lab, working through the questions is exactly what will help you get more practice with these topics and prepare you for Friday’s exam. Therefore I am assigning it as homework and giving you a couple days to work on it.


  • Work 32: Cleaning Up

    Due: Tuesday 5/14 10:00 am

    Submission Name: w32_clean.py

    • remove_punctuation(s)
      • Returns a new string that is s with all punctuation removed.
      • s.replace(a, b) will replace all occurrences of substring a in s with the new string, b.
      • We will define punctuation as any non-letter, non-number, and non-whitespace character in a string. Look at the full text to Alice in Wonderland to find examples.
      • The one exception is the apostrophe. We will keep it so that contracted words like isn’t remain.
      • For consistency you can use the following definition of punctuation:
        • punctuation = """.,!?"()“”_-:—;"""
    • word_counts(s)
      • This function will take a string containing text.
      • It will return a dictionary where each key is a word from the parameter, and the values will be the number of times that word appears in the string.
      • Before generating the dictionary, s should be converted to lowercase and have all punctuation removed.
      • Example: ``` tobe = ‘To be or not to be,\nthat is the question!’ word_counts(tobe) ==> {‘to’: 2, ‘be’: 2, ‘or’: 1, ‘not’: 1, ‘that’: 1, ‘is’: 1, ‘the’: 1, ‘question’: 1}
    • remove_commons(d, common)
      • This function takes a dictionary of word counts (like what is returned by word_counts) and a list of words.
      • It will remove any entry in the dictionary where the key is found in the list of words provided.
      • Example:
        common = ['the', 'be', 'to', 'of', 'and', 'a', 'in', 'that', 'have', 'i']
        tobe_counts = word_counts(tobe)
        remove_commons(tobe_counts, common)
        print(tobe_counts) ==> {'or': 1, 'not': 1, 'is': 1, 'question': 1}
        

  • Lab 04: Code Breakers!

    Due: Tuesday 5/14 10:00am

    All the instructions for this assignment can be found in efficiency.py after you click the link below to make a new repository.

    As always, you only need the tools we’ve discussed in class to solve these problems. If you use anything from outside of class, it should not trivialize (do the entire problem) for you. For example, Problem 2 involves finding the average of a list of value, there is a python function that does this, don’t use it.

    Sample output:

    ==========Problem 0==========
    {'j': 38980, 'x': 29048, 'u': 53082, 'q': 35125, 't': 18520, 'l': 4446, 'd': 28641, 'k': 13074, 'h': 24502, 'i': 27159, 'e': 33475, 'v': 8975, 'b': 17145, 's': 10500, 'a': 3542, 'c': 11787, 'r': 6363, 'o': 9431, 'y': 30138, 'w': 7888, 'f': 6798, 'm': 11266, 'n': 549, 'z': 452, 'g': 427, 'p': 149}
    
    ==========Problem 1==========
    {'j': 9.034399321377085, 'x': 6.732458478382801, 'u': 12.302821569454553, 'q': 8.140925504447669, 't': 4.292382643199169, 'l': 1.0304499585131484, 'd': 6.638128039085714, 'k': 3.0301625635629557, 'h': 5.678831507757346, 'i': 6.2946447195813295, 'e': 7.758504804594611, 'v': 2.080136837079511, 'b': 3.9736987266549546, 's': 2.4335862717921857, 'a': 0.8209297690178972, 'c': 2.7318744176775707, 'r': 1.4747532807060644, 'o': 2.185824012311629, 'y': 6.985087910406943, 'w': 1.828202715418739, 'f': 1.575573283394598, 'm': 2.6111221845724537, 'n': 0.12724179649656286, 'z': 0.10476009474762552, 'g': 0.09896584171954889, 'p': 0.03453374804733673}
    
    ==========Problem 2==========
    {'a': 8.2, 'b': 1.5, 'c': 2.8, 'd': 4.3, 'e': 12.7, 'f': 2.2, 'g': 2.0, 'h': 6.1, 'i': 7.0, 'j': 0.15, 'k': 0.77, 'l': 4.0, 'm': 2.4, 'n': 6.7, 'o': 7.5, 'p': 1.9, 'q': 0.095, 'r': 6.0, 's': 6.3, 't': 9.1, 'u': 2.8, 'v': 0.98, 'w': 2.4, 'x': 0.15, 'y': 2.0, 'z': 0.074}
    
    ==========Problem 3==========
    92.94840245954454
    
    ==========Problem 4==========
    [92.94840245954454, 99.52890081165896, 105.41944000166875, 88.57492947698753, 94.89885900032911, 96.47517051791351, 84.87751862736461, 105.49259314145854, 112.41802184665164, 91.24769092527268, 4.029584060705227, 90.97751343571395, 113.43765898734995, 106.63891332724549, 84.74697568267888, 97.64583472472664, 93.9439432024141, 88.36946990001437, 104.20787838094664, 100.22053488372092, 91.38099258335613, 82.47702236118127, 92.88041899866037, 95.24587264231843, 93.6103179932416, 82.44534911996885]
    
    ==========Problem 5==========
    <solution not posted>
    

  • Work 31: Definitions?

    Due: Thursday 5/9 10:00 am

    Submission Name: w31_dict.py

    lists2dict(g0, g1)

    • Takes 2 lists of equal size, and returns a dictionary where the keys are the elements of g0 and the values are the elements of g1.
    • Example:
      • lists2dict(['v', 'viii', 'iv'], ['empire strikes back', 'force awakens', 'new hope']) ==> {'v': 'empire strikes back', 'viii': 'force awakens', 'iv': 'new hope'}

    better_hitters(team, cutoff)

    • This function will take a dictionary where the keys are baseball player names and the values will be their current batting average, and a number representing the batting average for the entire league.
    • The function will return a list of player names with averages above or equal to the cutoff average.
    • exmaple:
      yankees = {'volpe': .250,
               'soto': .329,
               'judge': .222,
               'tores': .216,
               'rizzo': .265,
               'stanton': .227,
               'verdugo': .275,
               'trevino': .281,
                'cabrera': .250}
      better_hitters(yankees, .275) ==> [soto', 'verdugo', 'trevino']
      

    word_counts(s)

    • s is a string containing english text (like the text of a book).
    • Returns a dictionary where each key is a unique word from s, and the values are the number of times that word appears in s.
    • For the moent, assume that words can be easily found by splitting a string on any whitespace.
    • Use Alice’s adventures in wonderland, or another book, to test.
    • Here are the first few entries from Alice’s Adventures in Wonderland:
      • {'Alice’s': 11, 'Adventures': 2, 'in': 346, 'Wonderland': 2, 'by': 54,

  • Work 30: Literary Analysis

    Due: Wednesday 5/8 10:00 am

    Submission Name: w30_alice.py

    Make a Data Directory

    Since we will be working with external text files a lot over the next couple of weeks, you should create a directory called data/ in your github repository. For this assignment, we’ll be working with Alice’s Adventures in Wonderland by Lewis Carroll. You should download (after opening the link in your browser, go to the File menu and select “Save As”) the book and save it to this directory.

    Write a python program

    Some of these functiosn should work with any text, while others will be based off of using the copy of Alice’s Adventures in Wonderland you have downladed. For this assignment, you will be using the same text source for everything.

    • get_chars_after(s, key, n)
      • Return a string containing n characters starting from the first time key appears in s.
      • If key is not in s, return the empty string.
    • word_count(s, key)
      • Return how many times key appears in s.
    • get_words_after(s, key, n)
      • Return a string containing n words starting from the first time key appears in s.
      • If key is not in s, return the empty string.
    • get_chapter(s, chapter)
      • Return the entire text of chapter chapter form s.
      • Assume chapter is a roman numeral I to XII.
      • Look at the book so you’re clear how the chapters are structured, note that chapter 13 ends with THE END

    Write a python program that opens and reads Alice’s Adventures in Wonderland, and uses that text to test the functions above.


  • Work 29: Joining Forces

    Due: Monday 5/6 10:00 am

    Submission Name: w29_join.py

    Write the following python functions

    make_csv_string

    • This function will take a list of numbers, and return a string where each value is separated by a comma.
    • example
      • make_csv_string([90, 99, 97, 89]) ==> '90,99,97,89'

    make_csv_table

    • Take a list of lists, where each individual element may not be a string.
    • Returns a string where each sublist form the original becomes a comma separated string (like what make_csv_string creates), and each csv string is on its own line.
    • example
      g = [[90, 99, 97, 89], [91, 94, 99, 89], [81, 94, 100, 100], [90, 99, 79, 81], [50, 79, 49, 41], [90, 99, 94, 94]]
      print(make_csv_table(g))
      

      ==>

      90,99,97,89
      91,94,99,89
      81,94,100,100
      90,99,79,81
      50,79,49,41
      90,99,94,94
      

    make_html_list

    • Takes a list of any kind of data.
    • Returns the full HTML for an unordered list created form the parameter list. Each <li> element should be separated by a newline
    • example
      • print(make_html_list([90, 99, 97, 89])) ==>
      <ul>
      <li>90</li>
      <li>99</li>
      <li>97</li>
      <li>89</li>
      </ul>
      

    combine_data

    • Will take a string that looks like this:

      s = """90,99,97,89
      91,94,99,89
      81,94,100,100
      90,99,79,81
      50,79,49,41
      90,99,94,94"""
      
    • Returns a string where the values for each line are separated by , followed by a : and the averages value for that line.
    • example print(combine_data(s)) ==>
        90,99,97,89: 93.75
        91,94,99,89: 93.25
        81,94,100,100: 93.75
        90,99,79,81: 87.25
        50,79,49,41: 54.75
        90,99,94,94: 94.25
      

  • Work 28: Make Like a Banana and Split!

    Due: Thursday 5/2 10:00 am

    Submission Name: w28_split.py

    Write the following python functions

    get_values

    • This function will take a string containing numbers separated by spaces (' ') and return a list where each value is a number from the string, but represented as numbers, strings.
    • example:
      • get_values('90 99 97 89') ==> [90, 99, 97, 89]

    get_vals_list

    • This function will take a string with numbers, spaces, and newlines like this:
      s = """90 99 97 89
      91 94 99 89
      81 94 100 100
      90 99 79 81
      50 79 49 41
      90 99 94 94"""
      
    • It should return a list of lists, where each sublist corresponds to a line in the original string, and each value is an number represented as a number, not a string.
    • example gat_vals_list(s) ==>
        [[90, 99, 97, 89],
        [91, 94, 99, 89],
        [81, 94, 100, 100],
        [90, 99, 79, 81],
        [50, 79, 49, 41],
        [90, 99, 94, 94]]
      

    get_averages

    • This function will take a list of lists of numbers (like what get_vals_list returns) and return a list of averages for each sublist.
    • protip: there is a function sum(g) that will return the sum of the elements in g, as long as g only contains numbers.
    • example get_averages(get_vals_list(s)) ==> [93.75, 93.25, 93.75, 87.25, 54.75, 94.25]

  • Work 27: Help A Brother Out!

    Due: Thursday 5/2 10:00 am

    Submission Name: w27_towers.py

    Write a function that will print out instructions on how to solve the Towers of Hanoi problem, so the monks (or brothers) won’t need to think so much, and can focus on enlightenment instead.

    • hanoi(n, start, middle, end)
      • e.g. hanoi(4, 0, 1, 2)
    • Assume there are three towers, numbered 0, 1 and 2.
    • The goal is to get all the disks from tower 0 to tower 2.
    • Each printed line should be of the form: tower_a to tower_b denoting moving the top disk from tower_a to tower_b. For example, the solution for n=1 would be:
      • 0 to 2
    • The solution for n=3 would be:

      0 to 2
      0 to 1
      2 to 1
      0 to 2
      1 to 0
      1 to 2
      0 to 2
      
    • In order to test your solution you can use this website: http://homer.stuy.edu/~dw/hanoi/
      1. Select the number of disks and towers you want.
      2. Click the Re-initialize button.
      3. Paste your printed out instructions into the text box.
      4. Click the play moves button.
        • To make them move faster, set the speed slider to a smaller value (it’s more of a delay between moves slider, so the bigger the value, the longer it takes.).

  • Project 01: Fractal Function Flaunting

    Due: Friday 4/19 10:00 am

    Fractal Function Flair

    You will demonstrate your understanding of fractals by creating various of the three fractals we have made in class, and creating a webpage to share your work.

    Fractal Functions (python)

    You will have a single python program with (at least) 6 functions:

    • 3 functions will be the standard versions of the fractals we made last week (koch curve, sierpinski triangle, tree).
    • You will make a modified version of each fractal. A modified version means that something should change as the depth decreases. Here are some options to consider (though you may try others as well):
      • Changing the length of the lines.
      • Changing the width of the lines.
      • Changing the color of the lines.
      • Changing the angles used.
      • Adding/removing lines.
      • Adding/removing recursive steps.
    • Each modified version should have at least 2 modifications.
    • Amongst all your modifications, at least 2 should involve randomness.
    • You can also have extra functions if needed (like triangle).

    Showing Off (HTML/CSS)

    You will create a webpage to show off your fractals. Your page should have 3 sections, 1 for each fractal. Each section should include:

    • A picture of an example of the standard version of the fractal:
      • koch_curve(t, 4, 20)
      • sierpinski(t, 5, 200)
      • tree(t, 4, 50, 20)
    • An explanation of your modified version.
    • A picture of an example of your modified version.
    • The code for your modified version.
      • In HTML <code> is an inline element used to represent code. If you want to include multiple lines of code into a block element, you can put the <code> element inside a <pre> element. like this:
      <pre><code>
          def foo(x):
              return x**7
      </code></pre>
      
    • You should have some amount of custom CSS styling. But make sure the style does not get in the way of the page itself.
    • You can see a simple example (with no CSS) here: http://homer.stuy.edu/~jadw/fractals.html

    Submission

    • For this assignment you should have the following files:
      • fractals.py: The python program with all your code.
      • fractals.html: The HTML for your web page.
      • fractals.css: The CSS for your web page.
    • Include these three files in the github classroom repository for this assignment (links above).
    • Add fractals.html, fractals.css and the image files to your public_html directory so that your fractal webpage is publicly viewable.

  • Work 26: Arbor Day!

    Due: Monday 4/15 10:00 am

    Submission Name: w26_tree.py

    A fractal tree creates a pattern of branches recursively. Like the sierpinski triangle, it is important to keep track of the position of your turtle while drawing a tree.

    • The turtle should always end is the same position as where it started. This includes the location and heading.
    • At depth 1, a “tree” is just a trunk (straight line).
    • At depth 2, a tree is a trunk followed by 2 depth-1 trees. One tree to the right of the trunk and one to the left. The angle between the trunk a the subtrees can be provided as a parameter.

    Write tree(t, depth, length, angle), which will instruct turtle t to draw a fractal tree triangle where each branch is length long and each subtree is separated by angle degrees from its trunk.

    Here are some examples with a provided depth, each uses 30 for angle:

    • 1: tree 1
    • 2: tree 2
    • 3: tree 3

    Here is an animation of a turtle drawing a fractal tree with depth 4.

    tree


  • Work 25: Triangle Fun!

    Due: Friday 4/12 10:00 am

    Submission Name: w25_sierpinski.py

    The Sierpinski triangle is another fractal that can be drawn in a similar way to the koch curve.

    • At depth 1, it is one equilateral triangle.
    • At depth 2, it is 3 triangles, each with a side length that is half of the full triangle, positioned next to and on top of each other.
    • As with the koch curve, think recursively. Instead of drawing a simple triangle, think of what you’re drawing as another sierpinski triangle of one less depth level.
    • Unlike the koch curve, you need to pay attention to the position and heading of your turtle at the start and end of each depth level. In general, the turtle should end in the exact same position as when it started.

    Write draw_sierpinski(t, depth, length), which will instruct turtle t to draw a sierpinski triangle where each side is length long.

    Here are some examples with a provided depth:

    • 1: sierpinski 1
    • 2: sierpinski 2
    • 6: sierpinski 6

    Here is an animation of a turtle drawing a sierpinski triangle with depth 5. Notice the way the turtles moves after finishing each triangle.

    sierpinski

    (If you’ve been enjoying these, you can look at this list of fractals and see if you can recreate any others).

    Here is a simple triangle drawing function:

    def triangle(t, size):
        t.lt(60)
        t.fd(size)
        t.rt(120)
        t.fd(size)
        t.rt(120)
        t.fd(size)
        t.rt(180)
    

  • Work 24: Fractal Fun!

    Due: Thursday 4/11 10:00 am

    Submission Name: w24_koch.py

    The Koch Curve is a type of fractal. It can be drawn by a turtle as follows:

    • At depth 1, the curve is a straight line
    • At depth 2, the curve is:
      • A straight line,
      • followed by a rotation of 60 degrees to the left,
      • followed by another straight line
      • followed by a rotation of 120 degrees to the right
      • followed by another straight line
      • followed by a rotation of 60 degrees to the left
      • followed by one more straight line.
    • At depth 3…
      • This gets confusing fast, but look back at the depth 2 description and think recursively.
      • Instead of drawing a straight line, think of what you’re drawing as another koch curve of one less depth level.

    Write draw_koch(t, depth, length), which will instruct turtle t to draw a koch curve where each line is length long.

    Here are some examples with a provided depth:

    • 1: koch 1
    • 2: koch 2
    • 3: koch 3
    • 6: koch 6

  • Work 23: Turtle Power!

    Due: Tuesday 4/9 10:00 am

    Submission Name: w23_turtle.py

    Reminder

    Check yesterday’s post for information about Monday’s special Eclipse class.

    Write the following functions in python.

    draw_square(t, size)

    • Takes a turtle and a number as parameters.
    • Have the turtle draw a square with side length equal to the number parameter.
      • Exaple usage:
        leonardo = turtle.Turtle()
        draw_square(leonardo, 200)
        

    draw_spiral0(t, size)

    • Write a funtion that draws a stright spiral given a turtle and the length of the initial side.
    • A stright spiral is a sprial like shape made of sides that are straight lines at 90 degree angles to each other. Each side is shorter than the previous side.
    • A square spiral might look like this: square spiral

    draw_spiral1(t, size, angle)

    • Write a more generic spiral function, that will make a turtle draw a sprial shape given an initial side length and the angle it should turn each time.

    For reference, here’s a list of basic turtle commands. They’re here as comments so you can paste them to the top of your code, if desired. You can also look at the official turtle documentation.

    #    t = turtle.Turtle() # make a new turlte
    #    t.fd(<length>)
    #        t.fd(100)
    #    t.bk(<length>)
    #        t.bk(100)
    #    t.rt(<angle>)
    #        t.rt(45)
    #    t.lt(<length>)
    #        t.lt(45)
    #    t.position() # returns (x, y) coordinates of the turtle
    #    t.setx(<x coordinate>)
    #        t.setx(0)
    #    t.sety(<y coordinate>)
    #        t.sety(0)
    #    t.color((<red>, <green>, <blue>))
    #        t.color((255, 255, 0))
    

    Note for mac users:

    You may see the following warning in Thonny when running turtle code:

    WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
    

    You don’t need to worry about this. It’s a known issue but will not cause any problems.


  • Total Eclipse of the [Sun]

    On Monday, there will be a solar eclipse. While New York City will not see a total eclipse, we will be in line for 90% coverage (check out nasa’s nifty eclipse explorer map). This is a rare event, the next time NYC will be in the path of a solar eclipse will be 2079.

    The eclipse will be visible form approximately 2:15 - 4:30, with the peak being at 3:25pm. I want us all to have the opportunity to see this thing, so I’ve arranged a “Trip” with Ms. Prabhu to Rockefeller Park (the one next to Stuy) during our CS classes. Here are the details:

    • The trip will only last during your CS class period, you cannot use this to get out of your 9th or 10th period non-cs class.
    • Each period will meet on the first floor in the main lobby near the entrance.
    • We will walk out and return as a class.
    • YOU CANNOT LOOK DIRECTLY AT THE SUN, even during an eclipse. Ms. Prabhu and I will be providing eclipse glasses. You must return them to me at the end of class. (You can get your own free glasses from various places, included all Public Libraries, you don’t even need a library card).
    • I need to collect permission slips. Hand them in on Friday. I have given these out in class but you can also print them from here:

    You may want to look at GLOBE Observer, a NASA “citizen science” program meant to take place during the eclipse.


  • Work 22: Test Prep II

    Due: Thursday 4/4 10:00 am

    Submission Name: w22_test1.py

    Test Description

    The exam on Thursday will focus on the following major topics:

    • String slicing
    • Lists
    • for loops
    • map, filter and reduce
    • Other python topics may also be included.
    • The exam will have multiple choice questions and functions to write. It may have other short-answer type questions as well.
    • You can check out the class slides for review.

    Crowd-Sourced Review

    You can find all the submitted test questions here: https://github.com/mks22-dw/dwsource/tree/main/tests/test01

    Pick 4 of the programming questions to complete. At the beginning of each function you write, include the question number above as a comment. Be sure to include test cases with your program.

    You are encouraged to work on more problems to prepare for the exam. You should also take a look at the multiple choice questions. I have not vetted all the questions, so there may be mistakes.

    Optional Extra Review

    If you want more practice you should check out coding bat. Ignore any problems involving lists, or anything we haven’t covered in class.


  • Work 21: Questioning, The Return

    Due: Wednesday 4/2 10:00 am

    Submission Name: t01.py

    Test Description

    The exam on Thursday will focus on the following major topics:

    • String slicing
    • Lists
    • for loops
    • map, filter and reduce
    • Other python topics may also be included.
    • The exam will have multiple choice questions and functions to write. It may have other short-answer type questions as well.

    Write Possible Test Questions

    With your TableBuddy™ write two potential test questions.

    1. The first should be a multiple choice questions with 4 options.
    2. The second one should be a function to program.
      • This should be similar to the programming work you have had so far. Include all the information needed to write the function (formulas, etc).

    Put both questions, and the answers in a python file. You are working with your TableBuddy™, but both of you need to submit this file. You can put multiple lines together in a single comment using """ .... """. Use this format:

    """
    MC Question:
    
    Options:
    
    Answer
    
    =======================
    Programming question:
    
    Description
    
    Possible solution:
    =======================
    """
    

    Here is a filled in Example:

    """
    MC Question:
    What is the air speed of an unladen swallow?
    
    Options:
    A) 2 mph
    B) 20 mph
    C) 200 mph
    D) African or European?
    
    Answer: D
    
    =======================
    Programming question:
    
    Write a function that returns the ones
    digit of an integer.
    
    Possible solution:
    =======================
    """
    
    def one_dig(n):
      return n % 10
    

  • Work 20: What's in a Name?

    Due: Tuesday 4/2 10:00 am

    Submission Name: w20_names.py

    Use map, filter, reduce and lambda to answer the questions below. For some, you may need more than one line of code:

    Here is a list of the names of all the Major League Baseball teams, copy this into a python program:

    ['Los Angeles Angels', 'Oakland Athletics', 'Los Angeles Dodgers', 'San Diego Padres', 'San Francisco Giants', 'Tampa Bay Rays', 'Miami Marlins', 'Chicago Cubs', 'Chicago White Sox', 'Kansas City Royals', 'St. Louis Cardinals', 'New York Mets', 'New York Yankees', 'Cincinnati Reds', 'Cleveland Guardians', 'Philadelphia Phillies', 'Pittsburgh Pirates', 'Houston Astros', 'Texas Rangers', 'Arizona Diamondbacks', 'Colorado Rockies', 'Washington Nationals', 'Atlanta Braves', 'Baltimore Orioles', 'Boston Red Sox', 'Detroit Tigers', 'Minnesota Twins', 'Seattle Mariners', 'Milwaukee Brewers']
    
    1. Create a list that contains the length of each of the team names.
    2. Create a list that contains only team names that are less than 15 characters long.
    3. Create a list that contains the number of words in each team name.
      • So New York Yankees would be 3, while Detroit Tigers would be 2
      • s.count(' ') will return the number of times a space appears in string s. This will be helpful
    4. Find the number of teams with 2 word names.
    5. Find the number of teams with 3 word names.
    6. Create a string made by combining the second word of all the 2 word teams.

  • Lab 03: Lists

    Due: Thursday 3/28 10:00am

    All the instructions for this assignment can be found in efficiency.py after you click the link below to make a new repository.

    As always, you only need the tools we’ve discussed in class to solve these problems. If you use anything from outside of class, it should not trivialize (do the entire problem) for you. For example, Problem 2 involves finding the average of a list of value, there is a python function that does this, don’t use it.

    Sample output:

    ==========Problem 0==========
    list a:  10 [4, 7, 4, 1, 7, 9, 9, 7, 5, 5]
    list b:  10 [0, 7, 9, 4, 2, 3, 8, 9, 9, 5]
    ==========Problem 1==========
    test list:
    0: =========
    1: =====
    2: =====
    3: ===
    4: =
    5: =====
    6: =========
    7: =====
    8: =======
    9: ========
    
    list a:
    0: ====
    1: =======
    2: ====
    3: =
    4: =======
    5: =========
    6: =========
    7: =======
    8: =====
    9: =====
    
    list b:
    0:
    1: =======
    2: =========
    3: ====
    4: ==
    5: ===
    6: ========
    7: =========
    8: =========
    9: =====
    
    ==========Problem 2==========
    test list (5.7): 5.7
    list a: 5.8
    list b 5.6
    ==========Problem 3==========
    test list (4): 4
    ==========Problem 4==========
    test list (5): 5
    list a: 7
    list b: 9
    ==========Problem 5==========
    test list ([0, 1, 0, 1, 0, 4, 0, 1, 1, 2]): [0, 1, 0, 1, 0, 4, 0, 1, 1, 2]
    list a: [0, 1, 0, 0, 2, 2, 0, 3, 0, 2]
    list b: [1, 0, 1, 1, 1, 1, 0, 1, 1, 3]
    list c (values [0, 5) ): [3, 4, 1, 3, 3, 3, 4, 0, 0, 2]
    list c counts: [2, 1, 1, 4, 2]
    ==========Problem 6==========
    0: =====
    1: ======
    2: =
    
    0: ========
    1: =================================
    2: ==============================
    3: ==========================
    4: ====================================
    5: ===================
    6: ========
    7:
    8: ================
    9: =====================================
    
    ==========Problem 7==========
    <solution not posted>
    

  • Work 19: Do this for a while

    Due: Tuesday 3/26 10:00 am

    Submission Name: w19_loops.py

    • count
      • Using a for loop, write a function that will return the number of times a specific element appears in a collection.
        • Examples:
          • count(4, [1, 2, 3, 4]) ==> 1
          • count('a', 'abracadabra') ==> 5
    • doublify
      • Using for, write a function that will take a list of numbers and return a new list that contains the values from the parameter list doubled.
        • Example: doublify([6, 3, -8, 3.5]) ==> [12, 6, -16, 7.0]
    • add_ten
      • Write a function that takes a list of numbers and adds 10 to each element. The function should not return anything.
      • Example:
        g = [1, 2, 3, 4]
        add_ten(g)
        print(g)
        # Should print [11, 12, 13, 14]
        
      • Think before you code: should you use for in this function?
    • zip_lists
      • Write a function that accepts two lists as parameters and returns a new list.
      • The returned list should have the elements in alternating order that is:
        • a[0], then b[0], then a[1], then b[1] … until you run out of elements.
      • When one list is empty, then the remaining elements from the other list should be put at the end.
      • Examples:
        zipLists( [1,2,3] , ['a','b'] ) ==> [1,'a',2,'b',3]
        zipLists( [1,2] , [5,5,5,5] )   ==> [1,5,2,5,5,5]
        zipLists( [1] , [] )            ==> [1]
        

  • Work 18: The Return of HTML

    Due: Thursday 3/21 10:00 am

    Submission Name: w18_html.py

    Python + HTML

    You have written full web pages in html, but often, especially for larger websites, people don’t write all the html. Instead, they focus on writing the content and providing some information about its structure, and then rely on a computer program to generate the actual HTML. Today, you will write some functions that generate HTML. In order to make sure they are correct, you can paste the output into this HTML “playground”.

    make_link(url, anchor)

    • Assume url is a string containing a valid link, and anchor is a string.
    • Return a string containing a complete <a> tag using url and anchor
    • make_link('http://xkcd.com', 'xkcd') -> <a href="http://xkcd.com">xkcd</a>

    html_list(g)

    • Assume g is a list.
    • Return a string containing a full HTML unordered list <ul> containing the elements in g.
    • While not necessary for HTML, put newlines between each list item.
    • html_list(['cat', 'dog', 47]) ->
      • <ul>
        <li>cat</li>
        <li>dog</li>
        <li>47</li>
        </ul>
        

    link_list(links, anchors)

    • Assume links is a list containing valid urls.
    • Assumer anchors is a list the same size as links containing strings.
    • Return a string containing a full HTML unordered list <ul> where each item is a link using the corresponding elements from each list.
      • i.e. anchors[0] should be the text for links[0]
    • While not necessary for HTML, put newlines between each list item.
        us = ['https://www.stuycs.org/fcs00-dw/', 'https://github.com/mks21-dw/solutions', 'https://www.stuycs.org/dwlessons/fcs/selector.html']
        ts = ['class site', 'source code', 'slides']
        print(html_link_list(us, ts))
      
        <ul>
        <li><a href="https://www.stuycs.org/fcs00-dw/">class site</a></li>
        <li><a href="https://github.com/mks21-dw/solutions">source code</a></li>
        <li><a href="https://www.stuycs.org/dwlessons/fcs/selector.html">slides</a></li>
        </ul>
      

    make_table(data)

    • An HTML table organizes information in rows. The basic building blocks of tables are the table, tr, and td elements:
      • table: container for the entire table.
      • tr: container for a single row of a table
      • td: container for actual data in the table
      • here is a sample table with 2 rows:
        <table>
          <tr><td>a</td><td>b</td><td>c</td></tr>
          <tr><td>e</td><td>f</td><td>g</td></tr>
        </table>
        
    • Assume data is a list of lists, where each sublist is the same length.
    • make_table should return a string containing the full HTML for a table element. Each row of the table should be a single sublist of data.
        d = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
        print(make_table(d))
      
        <table>
        <tr><td>1</td><td>2</td><td>3</td></tr>
        <tr><td>4</td><td>5</td><td>6</td></tr>
        <tr><td>7</td><td>8</td><td>9</td></tr>
        <tr><td>10</td><td>11</td><td>12</td></tr>
        </table>
      

  • Work 17: Lists!

    Due: Thursday 3/21 10:00 am

    Submission Name: w17_list.py

    Write the following functions in python.

    For all of these functions, only use methods/structures we’re covered in class.

    • make_list_to_n(n)
      • Make and return a list of integers of all integers from 1 to n inclusive. They should be in increasing order.
        • make_list_to_n(0)[]
        • make_list_to_n(1)[1]
        • make_list_to_n(3)[1, 2, 3]
    • power_list(b, n)
      • Make and return a list of the powers of b from 1 to n, inclusive.
      • power_list(2, 5) -> [2, 4, 8, 16, 32]
    • make_sentence(g)
      • Assume g is a list containing strings that are non-empty and do not start or end with space
      • Take all of the strings in g, and combine them into one string, separated by spaces. Return that string
      • make_sentence([])''
      • make_sentence(['bob'])'bob'
      • make_sentence(['hot', 'dog'])'hot dog'
    • join_list(g, s)
      • Assume g is a list and s is a string.
      • Return a string containing all the elements of g, separated by s.
      • join_list([4, 18, 2], '-') -> '4-18-2'
      • join_list([1, 2, 3, 4], ' potato ') -> '1 potato 2 potato 3 potato 4' <!– makeFibList
      • Make a list of the Fibonacci numbers up to the nth term. The 0’th element is 0, the 1st is 1.
      • makeFibList(0) → [0]
      • makeFibList(1) → [0, 1]
      • makeFibList(2) → [0, 1, 1] –>

  • Work 16: Cut it Out

    Due: Wednesday 3/20 10:00 am

    Submission Name: w16_slice.py

    Write the following python functions using STRING SLICING

    Do not use any loops in these functions. Instead, use string slicing to solve each.

    • split_name
      • Takes a string representing a name as a parameter. Assume the string has a first and last name, separated by spaces, like "Eddie Vedder"
      • Should return a string with each part of the name on its own line
      • Example:
        >>> print(split_name("John Shaft"))
        John
        Shaft
        
    • bondify
      • Names sound cooler the way James Bond says them (“Bond… James Bond”), so we’ll write a python program to do that!
      • Takes a single parameter representing a name, the same format as splitName.
      • Should return a new string with the input name written Bond style.
      • Example: bondify("Mr DW") ==> "DW... Mr DW"
    • find_last
      • Takes 2 parameters, one representing a string and the second representing a character.
      • Returns the index of the last occurrence of the character in the string, or -1 if the character is not in the string.
      • Examples
        find_last( 'hello', 'l') ==> 3
        find_last('hello', 'h') ==> 0
        find_last('hello', 'z') ==> -1
        
    • replace
      • This function will take a string and replace part of it with something new
      • Takes 3 string parameters, The first represents the original string, the second represents the part you want to take out (key), and the last represents the replacement string.
      • Returns a new string that is a copy of the original except that the replacement string is located where the key use to be.
      • If the key is not in the original string, you should return the original, unmodified.
      • the .find() method will work with multi-character strings.
      • Example: replace("I abhor cs!", "abhor", "love") ==> "I love cs!"

  • Lab 02: Rot13

    Due: Tuesday 3/19 10:00am

    All the instructions for this assignment can be found in efficiency.py after you click the link below to make a new repository.

    Sample output (I’ve truncated some of the output, which you can see from ...):

    ==========Problem 0==========
    a: 97
    b: 98
    c: 99
    ...
    x: 120
    y: 121
    z: 122
    ==========Problem 1==========
    An actual answer should go here.
    ==========Problem 2==========
    b: o
    q: d
    ?: ?
    ==========Problem 3==========
    a -> n
    b -> o
    c -> p
    ...
    x -> k
    y -> l
    z -> m
    ==========Problem 4==========
    skywalker -> fxljnyxre
    An actual answer should go here
    ==========Problem 5==========
    b: o
    q: d
    B: O
    Q: D
    ?: ?
    ==========Problem 6==========
    Red 5 standing by! -> Erq 5 fgnaqvat ol!
    Erq 5 fgnaqvat ol! -> Red 5 standing by!
    

  • Work 15: Test Prep

    Due: Friday 3/15 10:00 am

    Submission Name: w15_test0.py

    Test Description

    The exam on Friday will cover the following major topics:

    • Python basics (variables, operators, functions)
    • Conditional statements (if, else, elif)
    • While loops
    • String basics (len, find, indexing, ord, chr)
    • The exam will have multiple choice questions and functions to write. It may have other short-answer type questions as well.
    • You can check out the class slides for review.

    Crowd-Sourced Review

    You can find all the submitted test questions here: https://github.com/mks22-dw/dwsource/tree/main/tests/test00

    Pick 4 of the programming questions to complete. At the beginning of each function you write, include the question number above as a comment. Be sure to include test cases with your program.

    You are encouraged to work on more problems to prepare for the exam. You should also take a look at the multiple choice questions. I have not vetted all the questions, so there may be mistakes.

    Optional Extra Review

    If you want more practice you should check out coding bat. Ignore any problems involving lists, or anything we haven’t covered in class. In general, you should have enough tools to do the problems in Warmup-1 as well as in the string and logic sections.


  • Work 14: Questioning

    Due: Thursday 3/14 10:00 am

    Submission Name: t00.py

    Test Description

    The exam on Friday will cover the following major topics:

    • Python basics (variables, operators, functions)
    • Conditional statements (if, else, elif)
    • While loops
    • String basics (len, find, indexing, ord, chr)
    • The exam will have multiple choice questions and functions to write. It may have other short-answer type questions as well.

    Write Possible Test Questions

    With your TableBuddy™ write two potential test questions.

    1. The first should be a multiple choice questions with 4 options.
    2. The second one should be a function to program.
      • This should be similar to the programming work you have had so far. Include all the information needed to write the function (formulas, etc).

    Put both questions, and the answers in a python file. You are working with your TableBuddy™, but both of you need to submit this file. You can put multiple lines together in a single comment using """ .... """. Use this format:

    """
    MC Question:
    
    Options:
    
    Answer
    
    =======================
    Programming question:
    
    Description
    
    Possible solution:
    =======================
    """
    

    Here is a filled in Example:

    """
    MC Question:
    What is the air speed of an unladen swallow?
    
    Options:
    A) 2 mph
    B) 20 mph
    C) 200 mph
    D) African or European?
    
    Answer: D
    
    =======================
    Programming question:
    
    Write a function that returns the ones
    digit of an integer.
    
    Possible solution:
    =======================
    """
    
    def one_dig(n):
      return n % 10
    

  • Work 13: Casing the Joint

    Due: Wednesday 3/13 10:00 am

    Submission Name: w13_case.py

    Write the following python functions

    • upcase
      • Takes a single character string as an argument and returns the upper case version of it.
      • If the string does not contain a letter, or it already is upper case, return the original string.
      • Examples:
        upcase('C') ==> 'C'
        upcase('3') ==> '3'
        
    • upstring
      • Takes a string as an argument, and returns a copy of the string where all the lower case letters are capitalized.
      • Examples: ``` upstring(‘hello’) ==> ‘HELLO’ upstring(“What’s up?”) ==> “WHAT’S UP?”

  • Work 12: I've Got the World on a String

    Due: Tuesday 3/12 10:00 am

    Submission Name: w12_string.py

    Write the following python functions

    • split_name
      • Takes a string representing a name as a parameter. Assume the string has a first and last name, separated by spaces, like "Eddie Vedder"
      • Should return a string with each part of the name on its own line
      • Example:
        >>> print(split_name("John Shaft"))
        John
        Shaft
        
    • bondify
      • Names sound cooler the way James Bond says them (“Bond… James Bond”), so we’ll write a python program to do that!
      • Takes a single parameter representing a name, the same format as splitName.
      • Should return a new string with the input name written Bond style.
      • Example: bondify("Mr DW") ==> "DW... Mr DW"
    • find_last
      • Takes 2 parameters, one representing a string and the second representing a character.
      • Returns the index of the last occurrence of the character in the string, or -1 if the character is not in the string.
      • Examples
        find_last( 'hello', 'l') ==> 3
        find_last('hello', 'h') ==> 0
        find_last('hello', 'z') ==> -1
        

  • Lab 01: Efficiency

    Due: Monday 3/11 10:00am

    All the instructions for this assignment can be found in efficiency.py after you click the link below to make a new repository.

    Sample output (you do not need to add commas to the loop count values. I’ve added them to make them clearer):

    euler5(10):  2520
    Testing loop count only:
    loop count:  25
    euler5(4):  12
    
    Timing slow version:
    loop count:  7,001
    euler5(10):  2520
    elapsed time:  0.0008640289306640625
    loop count:  648,974,495
    elapsed time:  75.16956925392151
    answer euler5(20):  232792560
    
    Better version:
    loop count:  51,473,642
    elapsed time:  5.883571147918701
    answer euler5(20):  232792560
    
    Best version:
    elapsed time:  0.0
    loop count:  88
    answer euler5(20): 232792560
    

  • Work 11: Pythons can be Eul-y

    Due: Wednesday 3/6 10:00 am

    Submission Name: w11_euler.py

    Task

    1. Go to http://projecteuler.net/problems
    2. Solve problems 1, 6 and 5
    3. If you’ve completed them, work on more.

    Important Notes

    • Your completed assignment should have the functions and test cases in it.
    • The functions you write should return the answer.
    • Some of these problems are simple, many of them are difficult.
    • For some of these problems it will be quite helpful to write multiple functions.
    • SUPER HELPFUL CODING TIP
      • Use print statements inside your loops to see what is happening to your variables
      • Some of your loops may intentionally go on for a while

    Here are solutions for the first 50 problems:

    Problem 001: 233168
    Problem 002: 4613732
    Problem 003: 6857
    Problem 004: 906609
    Problem 005: 232792560
    Problem 006: 25164150
    Problem 007: 104743
    Problem 008: 40824
    Problem 009: 31875000
    Problem 010: 142913828922
    Problem 011: 70600674
    Problem 012: 76576500
    Problem 013: 5537376230
    Problem 014: 837799
    Problem 015: 137846528820
    Problem 016: 1366
    Problem 017: 21124
    Problem 018: 1074
    Problem 019: 171
    Problem 020: 648
    Problem 021: 31626
    Problem 022: 871198282
    Problem 023: 4179871
    Problem 024: 2783915460
    Problem 025: 4782
    Problem 026: 983
    Problem 027: -59231
    Problem 028: 669171001
    Problem 029: 9183
    Problem 030: 443839
    Problem 031: 73682
    Problem 032: 45228
    Problem 033: 100
    Problem 034: 40730
    Problem 035: 55
    Problem 036: 872187
    Problem 037: 748317
    Problem 038: 932718654
    Problem 039: 840
    Problem 040: 210
    Problem 041: 7652413
    Problem 042: 162
    Problem 043: 16695334890
    Problem 044: 5482660
    Problem 045: 1533776805
    Problem 046: 5777
    Problem 047: 134043
    Problem 048: 9110846700
    Problem 049: 296962999629
    Problem 050: 997651
    

  • Work 10: While I Have Your Attention

    Due: Wednesday 3/6 10:00 am

    Submission Name: w10_while.py

    9th period: See notes below

    Write the following functions in python using while.

    • fizz_buzz(limit)
      • Loops through the integers in the range [1, limit]
      • If a number is a multiple of 3, print the number and fizz.
      • If a number is a multiple of 5, print the number and buzz
      • If a number is a multiple of 3 and 5, print the number and fizzbuzz! (this should not also print fizz and buzz)
      • Sample output:
        fizz_buzz(22)
        3 fizz
        5 buzz
        6 fizz
        9 fizz
        10 buzz
        12 fizz
        15 fizzbuzz!
        18 fizz
        20 buzz
        21 fizz
        
    • fizz_what(limit, fizz_num, buzz_num)
      • Works like fizz_buzz, but instead of 3 and 5, use fizz_num and buzz_num
      • Sample output:
        fizz_what(50, 6, 9)
        6 fizz
        9 buzz
        12 fizz
        18 fizzbuzz!
        24 fizz
        27 buzz
        30 fizz
        36 fizzbuzz!
        42 fizz
        45 buzz
        48 fizz
        
    • sub_digs(n)
      • Returns the sum of the digits in n.
      • Example: sum_digs(87243) ==> 24

    Special Notes on while

    Loops are one of the main ways we write code that repeats itself in python (in racket, it was recursion, in NetLogo it was a forever button). There are a couple of loop structures in python, we will start with while.

    While Loop

    while

      while boolean_expression:
          code
    
    • All code inside the while loop statement is repeatedly run as long as boolean_expression is True

    • Example:

      n = 10
      s = 0
      while ( n > 0):
        s = s + n
        print(n, s)
        n = n - 1
      print(s)
      

      Would print:

      10 10
      9 19
      8 27
      7 34
      6 40
      5 45
      4 49
      3 52
      2 54
      1 55
      55
      

  • Work 09: Conditional Responses

    Due: Tuesday 3/5 10:00 am

    Submission Name: w09_if.py

    Write the following functions in python.

    • max3
      • Has three parameters representing numbers.
      • Returns the largest value of the three parameters.
    • distance
      • Takes 4 parameters representing 2 (x, y) points.
      • Assume the order is (x0, y0, x1, y1)
      • Returns the distance between the two points.
      • Use the distance formula: sqrt( (x1 - x0)2 + (y1 - y0)2)
    • closer_point
      • Takes 6 inputs, each pair of inputs represents the (x, y) coordinates of a point on the cartesian plane.
        • Assume the order is (x0, y0, x1, y1, x2, y2)
      • Prints out which of the first two points is closer to the third point.
      • If both points are equidistant, print a message stating they are the same distance.
      • Sample output: (10, 10) is closer to (0, 0)
    • is_leap_year
      • Takes one parameter representing a year. Prints out if the provided year is a leap year or not.
      • Years divisible by 4 are leap years except if they are divisible by 100 but not divisible by 400.
      • Samples output: 2024 is a leap year.
    • Use the functions from yesterday’s assignment to test, you can refer to the posted solutions if you want.

  • Work 08: Getting Testy

    Due: Wednesday 2/28 10:00 am

    Submission Name: w08_tests.py

    RESET YOUR BRAIN

    Write the following functions in python.

    • test_1(f, expected, i)
      • Tests a function that has 1 parameter.
      • Takes as parameters a function, expected return value, and parameter.
      • Evaluates the provided function on the provided input. Prints out a message as to whether or not the function worked as expected.
      • Returns True or False based on if the provided function worked as expected.
      • Sample usage: test_1(f_to_c, 0, 32)
    • test_4(f, expected, i0, i1, i2, i3)
      • Tests a function that has 4 parameters.
      • Works the same way as test_1, just with more parameters
      • Sample usage: test_4(distance, 5.0, 3, 0, 0, 4)
    • Use the functions from yesterday’s assignment to test, you can refer to the posted solutions if you want.

  • Work 07: Funky Pythons

    Due: Tuesday 2/27 10:00 am

    Submission Name: w07_funcs.py

    RESET YOUR BRAIN

    Write the following functions in python.

    • distance
      • Calculate and return the Euclidean distance between the coordinates given as parameters.
      • Distance Formula: sqrt( (x1 - x0)2 + (y1 - y0)2)
        • To calculate a square root use: a**0.5
      • Examples:
        distance(3, 0, 0, 4) → 5.0
        distance(1, 0, 2, 0) → 1.0
        distance(0, 0, 8, 15) → 17.0
        
    • f_to_c
      • Write a function to convert Fahrenheit temperatures into Celsius.
      • Celsius = (f - 32) * (5/9)
      • Examples
        f_to_c(32.0) → 0.0
        f_to_c(212.0) → 100.0
        f_to_c(-40) → -40.0
        
    • eval_quadratic
      • Write a function that evaluates a quadratic equation in the form Y = aX2 + bX + C.
      • It accepts the parameters in the order a b c x, and returns the y value.
      • Examples
        eval_quadratic(1, 0, 3, 1) → 4
        eval_quadratic(1, 2, 3, 1) → 6
        eval_quadratic(1, 0, 3, 2) → 7
        
    • is_even
      • Determine if n is even, return True when it is, False otherwise.
      • Examples
        is_even(12) → True
        is_even(11) → False
        is_even(0) → True
        

  • Project 00: Further Enlightenment'

    Due: Thursday 2/28 10:00am

    Submission Name: See below for instructions

    Sample of different CSS styles and site layout: http://homer.stuy.edu/~jadw/site/

    Project Overview

    • This is an extension of w05_subject.
      • If you would prefer to change the subject of this website, you may.
    • You’re going to turn your subject specific page into a larger web site! At a minimum, your site should have the following files:
      • A main landing page:
        • This page should explain what your site is about, a general overview of the subject.
      • A page for each section from your original subject page
        • This means you should have at least 3 such pages.
        • You should add more detail to each section.
      • A single css file used by all your pages.

    Implementation Specifics

    • The list at the beginning of your subject html page should turn into a horizontal or vertical menu where each list item is a link to the respective page.
      • You should put this list inside a nav element.
      • The position, layout, coloring etc of the menu should be all done using css.
      • The navigational menu should indicate in some way what page is currently being viewed.
      • The navigational menu should also contain a link to the main landing page.
    • All image sources should be image files instead of links.
    • The entire project (html files, css, images) should be in a subfolder of your public_html folder called site. With the following required parts:
      • index.html: The main landing page for your site.
      • All other html files, and your css file.
      • images/: a further subfolder containing all the image files used by your site.
      • Here is an example of what the structure of your site folder should look like:
        ~/public_html dw$ tree site/
        site/
        ├── images
        │   ├── img0.png
        │   ├── img1.jpg
        │   ├── img2.png
        │   └── img3.gif
        ├── index.html
        ├── mystyle.css
        ├── p0.html
        ├── p1.html
        └── p2.html
        

    Evaluation

    You will be evaluated on the following:

    • Technical aspects
      • appropriate use of html and css
      • correct directory structure
      • correct use of public_html for publication as well as placemen tin your GitHUb repository.
    • Styling
    • Content
    • You must be the author of all the content, html and css for your website. You cannot use any web authoring tools that automatically generate html or css code.
    • Do not include any javascript.

    Further Resources

    You will want to go back over the HTML and CSS links from the previous 2 assignments. You may also find the following resources helpful:


  • Work 06: Stuylin' and Profilin'

    Due: Tuesday 2/13 10:00 am

    Submission Name: w06_style.css

    Remember, all website work should be in your web repository:

    Helpful resources:

    CSS Time

    Create a css file called w06_style.css in your web repository. This will be a style file used on your webpage for w03.html.

    • In this file you must set at least one css property for each element in the html file except for head and anything in head.
    • This file should have at least one example for each of the properties in this table.
    • Add your css file to the html file w03.html.

    Notes About Working From Home

    • Your home computer is probably not set up as a webserver, this is fine, but it means you’ll have to work a little differently than at school. First off, you will need a text editor and a web browser. I suggest pulsar as your text editor. You must use a plain text editor, so something like word or google docs is NOT acceptable.
    • Open your HTML and CSS files in your text editor, this is where you will edit them.
    • Also open your HTML (not the CSS, it will be included via the HTML file) in your web browser. Open it via the Open File option in the File menu of your browser. The address bar will start with: file:/// followed by the path to your HTML file.
    • As you edit your CSS, reload the HTML file in the browser. You may need to do a force reload (on firefox, that’s ctrl-shift-r)

    Pulling Work From Home Onto the Stuy Web Servers

    • First, make sure your updated work is on GitHub, however you can make that happen (either via the command line, pulsar, web interface …)
    • Once that’s done, then you known the work is uploaded to your repository, so now you need to pull it onto the stuy computers.
    • Open the command line environment on your computer.
      • On a MacOS or Linux computer, open the Terminal program.
      • On a Windows computer, open the Command Prompt program.
    • Connect to a stuycs server using ssh.
      • Use the following command: $ ssh USER@homer.stuy.edu replace USER with your cs lab username.
      • Enter your password when prompted (you may also need to agree that you trust the server).
      • If this worked, then you will have a command line identical to one you would open up using the terminal at school. You are now connected to the school computer. Any commands you run will be based on your school account, not your home computer.
    • cd into your public_html directory and use $ git pull to download any changes from GitHub.
    • If you cannot connect to homer, you can try these servers instead:
      • $ ssh USER@bart.stuy.edu
      • $ ssh USER@lisa.stuy.edu
      • $ ssh USER@marge.stuy.edu

    In case of emergency, break glass

    • Zoom link for potential remote class.

  • Work 05: Enlighten Us

    Due: Monday 2/12 10:00 am

    Submission Name: w05_subject.html

    Remember, all website work should be in your web repository:

    Helpful resources:

    Make a web page for something about which you are knowledgeable (could be anything, an academic subject, sport, music, theater, movie, comic …). The page should not be an exhaustive report on the subject, but provide some information in a coherent framework. Your page should include the following parts:

    • A main title/heading
    • A table of contents made of an unordered list.
      • list element: <ul> and <li>
      • You should have at least 3 sections listed.
    • Sections of text that correspond to each element in the table of contents.
      • Each section should start with a <h2> tag.
      • The text for each section should be in a <p> tag.
      • Each section should contain at least one link: <a>
      • Feel free to add pictures: <img>

    Notes:

    • You may be tempted to do things to modify the look of your page. Do not. Focus on the structure of the page, for that is what HTML is designed to do. We will work on making pages look fancy using CSS, at which point you can go nuts
    • If you want to work on this at home with the same tool presented in class, you can download and install pulsar.
    • You will have to configure and set SSH keys on your home computer in order to use the git integration tools in pulsar. You can follow instructions form the class notes about this, they will be similar for windows, but you’ll have to use the command prompt, and you should pay attention to where it stores your keys.

  • Work 04: Indexing Work

    Due: Thursday 2/78 10:00 am

    Submission Name: index.html

    Remember, all website work should be in your web repository:

    Helpful resources:

    Create an Index Page for your Websites

    Create a new html file names index.html. This file should contain the following things, in order:

    • Your name (h1).
    • Your class period (h2)
    • A list of the assignments in your public_html directory. Each list item should be a clickable link to the assignment file. You will update this list as we add more web pages, but at this time, you should have the following files:
      • hello.html (the basic text file disguised as html)
      • w03.html (the file that demonstrates tags)
      • index.html (this new file). You should also take this opportunity to make sure that the work you have is in the correct place and that you are using github correctly.

  • Work 03: Tag it Up

    Due: Wednesday 2/7 10:00 am

    Submission Name: w03.html

    Remember, all website work should be in your web repository:

    Helpful resources:

    Write a real Web Page

    Write a simple html file, properly formatted (which means include the non-visible html tags like DOCTYPE html head and body), that uses the following elements (you can include others if you’d like):

    Submission Notes

    Make sure your page is in your public_html directory on your school computer and added to your github repository as well. If you work on this from home, after you’ve uploaded your changes to GitHub, you’ll have to pull them onto your local home directory at school. How do you do that? The magic of ssh:

    • First, open the command line environment on your computer.
      • On a MacOS or Linux computer, open the Terminal program.
      • On a Windows computer, open the Command Prompt program.
    • Connect to a stuycs server using ssh.
      • Use the following command: $ ssh USER@homer.stuy.edu replace USER with your cs lab username.
      • Enter your password when prompted (you may also need to agree that you trust the server).
      • If this worked, then you will have a command line identical to one you would open up using the terminal at school.
    • cd into your public_html directory and use $ git pull to download any changes from GitHub.
    • If you cannot connect to homer, you can try these servers instead:
      • $ ssh USER@bart.stuy.edu
      • $ ssh USER@lisa.stuy.edu
      • $ ssh USER@marge.stuy.edu

  • Work 02:

    Due: Monday 2/5 10:00 am

    Submission Name: hello.html

    FYI: Class slides are now available here: https://www.stuycs.org/dwlessons/fcs/selector.html (this is also linked on the front page)

    Create your web page work repository

    This semester, we will have a separate GitHub repository for all our web page work (HTML and CSS files). Create that new repository by following the correct link below:

    Add a file

    Through the web interface, create a file called hello.html. Add a single line of text of your choosing to the file (perhaps the classic hello, world, my preferred Good news, everyone!, or anything else )


  • Work 01: Commanding Authority

    Due: Friday 2/2 10:00 am

    Submission Name: w01_commands.txt

    Create your work repository

    All Assignments will be submitted via GitHub classroom. Labs and projects will have their own assignment links, all homeworks should be submitted in the homework repository. Create your homework repository by following the appropriate link:

    Create a directory structure

    On school computers, create the following directory structure starting in your home directory.

     $ tree marvel/
     marvel/
     ├── heroes
     │   ├── avengers
     │   │   ├── black_widow.txt
     │   │   └── hulk.txt
     │   └── xmen
     │       ├── storm.txt
     │       └── wolverine.txt
     └── villains
         ├── hydra
         │   └── red_skull.txt
         └── thanos.txt
    
     5 directories, 6 files
    
    • In a plain text file, write down the exact sequence of commands you used to do this, putting each command on its own line.

  • Work 00: Getting to know you

    Due: Wednesday 1/31 10:00 am

    1. Please fill out the student info form found here: https://forms.gle/ShcY4hjt5BF9CvPn8
    2. You will need a GitHub account in order to submit work for this class. If you don’t have one already, go to https://github.com/ and create one.
      • If you attach it to your stuy.edu email address, you can sign up for the GitHub Student Developer Pack. It includes access to a bunch of programming tools/services. It is not required that you sign up for it.
    3. Read and acknowledge the Stuyvesant Computer Science Lab and Network Usage Policy