Courses‎ > ‎Intro to CS - Full Year‎ > ‎Spring‎ > ‎Dyrland-Weaver‎ > ‎

Work

Unless otherwise noted, all assignments are due by 8am the next class day.

All submissions must be made via the homework server: http://bert.stuy.edu/jdyrland/spring2019/pages.py?page=profile

Late homework can be submitted for half credit up until solutions have been posted.

You can find homework solutions here: https://github.com/mks22-dw/python

Work 41: 5/23

posted May 23, 2019, 11:05 AM by JonAlf Dyrland-Weaver

Attached to this post are two files that contains (fake) lists of student names and grades. tests.csv contains test grades while work.csv contains homework grades. Each line has the name of a student followed by the grades. Each piece of data is separated by a comma. For example:
            Han,85,86,85,84,82,88,93,82,93,82
            Han,1,0,1,1,1,1,1,0.5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Write functions to do the following, based on this file:

  • grades
    • Read in the file and return a dictionary where each key is a student's name and the value is a list containing that students grades.
    • Takes a single parameter representing the name of the file to be read
    • The list should contain numbers, not strings.
    • Here is a small example of what the dictionary should look like:
      • { 'Han': [85, 86, 85, 84, 82, 88, 93, 82, 93, 82] }
      • { 'Han': [1, 0, 1, 1, 1, 1, 1, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] }
  • averages
    • Takes a dictionary, formatted like the return value from grades, as a parameter
    • Returns a different dictionary where each key is a student's name, and the value is the average of all their grades.
    • For example:
      • { 'Han': 86.0 }
      • { 'Han': 0.76 }
  • full_grade
    • Takes 2 dictionaries created from the average function. One should contain the test averages, the other the homework averages.
    • Returns a dictionary where each key is the name of a student and the value is the grade for that student.
    • 70% of a student's grade comes from their test average, while 30% comes from their homework average.
      • For example, Han has a test average of 86 and a homework average of 0.76, so his grade would be 83
        • .86 * 70 + .76 * 30
    • Example dictionary element:
      • { 'Han': 83 }

IMPORTANT NOTE:
    This assignment does not include questions about html forms, but they will be on the test, so study that as well!

submit this as test5_review

Work 40: 5/21

posted May 21, 2019, 11:02 AM by JonAlf Dyrland-Weaver

One last madlibs variant
  • Create a form that allows the user to pick between at least 2 different madlibs stories and word lists using a drop-down list (select tag)
  • This form should send the data to your madlibs program and then respond with the corresponding madlibs page. You should need to do very little (or nothing) to your old madlibs_1.py program.
  • Make sure the form is accessible via the name madlibs.html
Submit this form as madlibs_form

Work 39: 5/20

posted May 19, 2019, 8:45 PM by JonAlf Dyrland-Weaver

  1. In a file called form0.html, that should be in public_html and accessible as a webpage:
    1. Write an html form that has 2 text boxes and a submit button.
      1. Write a python program that accepts input from the form and displays it. It should display the values entered, not the entire FieldStorage object.
    2. Once you have a working html/python program for those 2 inputs...
    3. Look at the different valid type attributes for the input tag: https://www.w3schools.com/tags/att_input_type.asp
    4. Include 2 new input types into your form (they can be any type), and have your python program display their values as well.
Submit the html code under form0

Work 38: 5/15

posted May 15, 2019, 11:37 AM by JonAlf Dyrland-Weaver   [ updated May 16, 2019, 11:06 AM ]

Make a new website version of madlibs that uses query strings to select the story and words files.
Submit the python code as madlibs_q

Work 37: 5/12

posted May 13, 2019, 10:56 AM by JonAlf Dyrland-Weaver

Make a webpage version of your python program.
  • The madlibs story should be different from the one I've provided.
  • Read in the story from a text file.
  • Read in the word options from a csv file.
  • This time create a webpage with all the required elements including, but not limited to
    • DOCTYPE, head, title, html, body
    • Also, including styling to your story to make your page more interested.
  • Submit your python code only (not the 2 text files) to the homework server.
  • Make sure your web page is accessible via:
    • http://homer.stuy.edu/~YOU/madlibs.py
Submit this as madlibs_1

Work 36: 5/10

posted May 10, 2019, 11:02 AM by JonAlf Dyrland-Weaver

  • Create a python program named web_test.py that prints out a string and a random number, that's it.
  • Perform all the necessary actions to make this program work as a web page.
    • You should be able to get to your website with a url that looks like the following: http://homer.stuy.edu/~dw/web_test.py
    •  Obviously replace dw with your username.
Submit this file as web_test

Work 35: 5/7

posted May 7, 2019, 10:53 AM by JonAlf Dyrland-Weaver

Modify your madly program from yesterday to use split and join.
  • When you read in the text file, use .split() to create a list
  • Use that list to replace words (this should be a simpler operation than before)
  • When the main loop of your and libs replacement his done, you should have a list containing all the words of the original text with the placeholder words replaced.
  • Use .join() to create a single string based on the list.
Update your submission to mardlibs with this new version.

Work 34: 5/6

posted May 6, 2019, 11:06 AM by JonAlf Dyrland-Weaver   [ updated May 6, 2019, 11:39 AM ]

REMINDER: Re-submit cypher_0 and cypher_1. Regardless of whether you did these on time, you must submit them again!

Mad Libs!

Mad Libs are stories where certain words are left blank and then replaced by someone who doesn't know the story. Here is a one sentence example:

"When you're ________ in a ______________ in _________ and it's __________ make sure to bring your _______" 
                       verb             weather type         city                      holiday                                          noun
Could become:
"When you're eating in a tornado in Brooklyn and it's flag day make sure to bring your toilet"

You will write a python program to fill in mad libs. You will need the following:
  1. A file that contains a story, but instead of blanks there is a placeholder. Get this file to start: https://github.com/mks22-dw/python/blob/master/text/tobe.txt
  2. A dictionary with keys that are word types and values that are lists of words of the type.
    • Put at least 5 words in each list, feel free to put more than 5.
    • For our above example, we might have the following dictionary:
      •  { 'verb' : ["eating", "swimming", "bathing", "lost"],
      •    'weather' : ["heat wave", blizzard", "hurricane", "rain"],
      •    'city' : ["Phoenix", "Brooklyn", "Toledo", "Juarez"],
      •    'holiday' : ["rosh hashannah", "flag day", "eid", "easter"]
      •    'noun' : ["toothbrush", "towel", "cat", "toilet"] }
  3. A function that returns a random element from a dictionary formatted like the one above. It should take 2 arguments, the dictionary and the key associated with the list you want an element from.
Once you have all of those pieces in place, you can do the actual mad libs part. You can code this any way you'd like, including adding extra functions, lists or variables, but you should follow the following general steps:
  1. Read the story from the given file into a string.
  2. Replace each placeholder word in the string with a randomly selected word from the appropriate word list.
  3. Print out the result.
When you run the program, it should print out a completed mad lib based on your story and the word dictionary

submit your python file and story file as madlibs

Work 33: 5/3

posted May 3, 2019, 11:21 AM by JonAlf Dyrland-Weaver

submit this as cypher_1

Work 32: 5/2

posted May 2, 2019, 11:34 AM by JonAlf Dyrland-Weaver

submit this as cypher_0

1-10 of 43