Programming with Python

Cassandra Tryhub
3 min readApr 4, 2018

--

Learning the basics of code

In collaboration with IEEE Toronto, the IEEE Ryerson Computer Chapter hosted a series of Python coding workshops. During these series of workshops, the focus is on building a program that is able to analyze tweets by Donald Trump. When you complete all the workshops, you will earn a certificate from IEEE Toronto!

Screenshot from my computer. Source: Cassandra Tryhub

The workshop series begins with the basics. While you may believe that you’ll walk in coding like this:

GIPHY

It might look like this:

GIPHY

Or this.

GIPHY

But not to worry! Armed with Python 3.6, Atom and our instructor Ali, the program was created over several sessions.

Workshop 1 and 2

Workshop one began with the basics of Python. We explored how to open command prompt, access files, and break down a tweet into individual words. Once we created a list of words from the tweet under the variable “tweet_words”, the goal was to calculate the number of items and print the result.

Screenshot of my computer while using Command Prompt to run the script. Source: Cassandra Tryhub

Building on this knowledge, workshop 2 was focused on determining whether it was a good or bad tweet. Numerical values were assigned to individual words. The value of the tweet will increase or decrease based on the number of words present from the directory we created. The “for” and “if, then” functions were used. Common errors that arise with these functions are improper indentations when giving the command.

Screenshot of my computer using Atom. Source: Cassandra Tryhub

Workshop 3

To make the code more complex, it is necessary to create a dictionary to assign values for the words. Although “good” and “great” are both considered good words, a higher value would be assigned to the word “great.” The sum of the words in the tweet are printed when the program runs. The tweet is analyzed as a good or bad tweet as well.

Screenshot of my computer using Atom. Source: Cassandra Tryhub

The code above was run on Command Prompt. The overall value of the tweet was assigned as 0.04193548387096774.

Screenshot of my computer using Command Prompt. Source: Cassandra Tryhub

Workshop 4

Screenshot of my computer using Atom. Source: Cassandra Tryhub

To avoid confusion, where similar words are classified as different (ex. tax and taxes), words will be shortened to their root form using “stem”. Nltk (natural language toolkit) will also be installed. With nltk, you will be able to tokenize each tweet. This function splits the tweet into its individual words in order to evaluate the tweet. The functions stemmer.stem and word_tokenize were used for this purpose.

Workshop 5

This workshop continues to build on the program from workshop 4. In the workshop, we learned how to program the file to read tweets from an outside source. The outside sources were saved as json file and a text file. The program evaluates each tweet as good or bad, as previously done in past workshops.

Screenshot of my computer using Atom. Source: Cassandra Tryhub

Upcoming Workshops

In the upcoming workshops, the program will be modified to receive data from live tweets using Twitter API. At this point, the code will be complete!

So get on your computer, learn the basics, and start programming!

GIPHY

--

--