RWET: Assignment 4

Today was the day I had to confront the very beginner like nature of my python coding skills.

Primarily because the assignment was to adapt a previous form of code that we had written and change the repeating parts into a function. In class this seemed fairly straightforward (and very useful).

So I returned to my midterm code [LINK]. I was thinking about breaking up the part that stripped the punctuation and the part that got rid of the boring words but I struggled with figuring out how the code would be broken up, because it seemed like everything was dependent on everything else – where do I make the breaks? Which, I guess is a lot of how code works. So how to make something modular.

I met with Allison and she explained that at their most basic, functions are a way of passing information in and outputting something else. Writing it here, it sounds so obvious. But taking these specific items of code and abstracting it into input and output was not quite as easy as I initially assumed.

A big part of my code was taking lists and altering them to make new lists. So we took the part of the code that stripped the punctuation and rewrote it as a function and then where it previously existed in the code we called what the function returned. Then we did this again with the boring words constructor function.

So far so good.

But rather than simply print the hardcoded Fib sequence as I had previously (print good_words[0], print good_words[1], print good_words[1], etc.) we tried to figure out a way that would take a number (n) and figure out the corresponding fib sequence number (so in this case, starting with 1: 1 = 1, 2 = 1, 3 = 2, 4 = 3, etc.). Use the properties of a list and a while statement to check each time if fib(n) was less than the length of lines, to print those lines and to break when it was more.

I added this to the bottom of the code, ran it in in terminal with sea_rose.txt and it worked!


Here’s the code:

(Visited 22 times, 1 visits today)

08. April 2016 by zoe.bachman.itp
Categories: RWET | Leave a comment

Leave a Reply

Required fields are marked *