Building your <Python> Knowledge

Tenicka Terell Norwood
5 min readFeb 4, 2023

--

With assistance from chatGPT

Photo by Hitesh Choudhary on Unsplash

Since the launch of chatGPT, it has been celebrated and denigrated for its ability to generate human-like responses. The speed of responses, the ability to regenerate responses, and the unchecked confidence in the answers generated by this system engendered much fear among several folks in academia. The bans came swiftly, from small liberal arts colleges to large pre-K — 12 school districts, with leading voices shouting to the rafters that education must be shielded from the dangers posed by this new tool that could seemingly create solutions that teachers could not assess as non-student-generated.

My mind did not go off in that direction. Instead, I began to wonder what I could use chatGPT to learn. I started building prompts. My first prompts were about poetry; I wanted to see if chatGPT could write about specific content in a style of my choice. Naturally, I chose to poke fun at one of my favorite people who prefers R to Python and chose a poem that counters his favorite argument.

Prompt 1: Write a poem with three stanzas in iambic pentameter about the benefits of Python compared to R:

Prompt 1 Result:

In data science, choices must be made,
Two languages stand out, well refined,
Python and R both with strengths displayed.

Python is versatile, strong and nimble, With vast libraries, easy to handle,
For any task, it is the symbol. R is a master at statistics,
With packages that make data analysis,
So much easier and truly fantastic.

So when it comes to data science work,
Consider Python, for it will never shirk,
And your projects, it will always perk!

-ChatGPT generated poem

I was hooked but wanted to build content-specific knowledge, so I tried a more python-centered prompt next.

Prompt 2: Craft the solution to 5 intermediate data science problems using PEP8 compliant python code:

Prompt 2 Result:

ChatGPT warns that the following code is simply a starting point, and how the dataset is related to the problem of interest affects the actual implementation of each stage of this protocol:

Load and Explore a Dataset

ChatGPT generated python script/How to Load and Explore a Dataset

Clean and pre-process data

ChatGPT generated python script/How to Clean and Pre-process the data

Visualize data

ChatGPT generated python script/How to Visualize the data

Splitting the Data into Training and Testing Sets

ChatGPT generated python script/How to Split data into training and testing sets.

Building a Machine Learning Model

ChatGPT generated python code to build and evaluate a machine-learning model.

While this output seemed clear and concise, I wanted to push the prompts further to see how ChatGPT could be used to extend my python knowledge. So I created a prompt to build a 2-hour course to develop my python knowledge.

Prompt 3: Write a short 2-hour course with guided lessons to familiarize me with basic data types and variables in Python, including sample code snippets that are pep8 compliant and follow the DRY principle.

Prompt 3: Result

2 Hour Course: Getting Familiar with Basic Data Types and Variables in Python

Introduction
This course aims to provide a comprehensive overview of basic data types and variables in Python and equip participants with the skills to write clean, PEP8-compliant, and DRY code.

Session 1: Basic Data Types (1 Hour)

  • Overview of basic data types in Python, including integers, floating-point numbers, strings, and booleans.
  • Participants will learn how to define and manipulate variables in Python, as well as how to convert between different data types.
  • Guided practice exercises will be provided to reinforce learning and ensure participants understand the concepts.

Session 2: Variables and Data Types in Practice (1 Hour)

  • Participants will work with real-world data sets and apply the concepts learned in the previous session to solve practical problems.
  • They will be introduced to the importance of writing clean, PEP8-compliant, and DRY code and using best practices to avoid common coding errors.
  • A review of the concepts learned in the course will be provided, along with a question and answer session to address any remaining questions or concerns.

Conclusion:

  • At the end of this course, participants will have a solid understanding of basic data types and variables in Python and be able to write clean and practical code.
  • The guided practice exercises and real-world examples will help them gain practical experience, and the review and question and answer session will provide a comprehensive overview of the key concepts learned in the course.

I asked for a follow-up to this lesson to illustrate the guided practice.

Prompt 4: Give me an example using python code for the Guided Practice Exercises in session 1.

Prompt 4: Result

ChatGPT generated python code guided practice for session one on basic data types in Python.

For completeness, I rounded off my questions to include a prompt to determine what ChatGPT thought I should learn in session 2.

Prompt 5: Give me an example using Python code of the Guided Practice Exercises in session two.

Sure, here’s an example of guided practice exercises for the basic data structures in Python:

  1. Lists:
  • Create a list of 5 numbers and perform the following operations:
  • Sort the list in ascending order
  • Reverse the list
  • Remove the last element from the list
ChatGPT generated python code for guided practice on creating lists.

2. Tuples:

  • Create a tuple of 5 numbers and perform the following operations:
  • Retrieve the second element from the tuple
  • Check if a number exists in the tuple
ChatGPT generated python code for guided practice on tuples.

3. Dictionaries:

  • Create a dictionary with keys as numbers and values as their squares and perform the following operations:
  • Retrieve the value for a given key
  • Update the value for a given key
  • Remove a key-value pair from the dictionary
ChatGPT generated python code for guided practice on dictionaries.

4. Sets:

  • Create two sets of numbers and perform the following operations:
  • Union of the two sets
  • The intersection of the two sets
  • The difference of the two sets
ChatGPT generated python code for guided practice on Sets.

The ChatGPT-generated lessons and guided exercises with code snippets seem like reasonable responses, but I am still learning and trying to determine ways to assess the output.

What‘s my next step?

I want to build a more robust analysis of prompt construction for ChatGPT:

  • I want to create a set of Jupyter notebooks to create a set of guided practices based on the feedback from ChatGPT.

Contact Me

If you would like to be updated with my latest articles, follow me on Medium. You can also connect with me on LinkedIn or email me at tenicka.norwood@gmail.com.

--

--

Tenicka Terell Norwood

Focus not on the intention, but on the impact and value of your insights. I help learners combine their domain knowledge with design thinking principles.