Wordle Helping Program
Jump to navigation Jump to search
- Computer Programming is only limited to your imagination. That is the magic of computer programming. However, in a computer science class, which was hell for me, they made us write programs that are totally worthless. The purpose of this program is to figure out the word faster. I will give it to you in sections that are useable. by themselves. In this exercise, I will go through the thought processes of making a Wordle "helping program." If you are not familar with the program, you can put an app on your smartphone or there is an online version.
Make a plan that is not overwhelming
- The goal here is to read one of the files.
- Download a list of words from the internet. A standard MS Excel format is csv, which stands for comma separated format. It means words separated by commas. You can click one here.
- Open up the zip file. You will notice that it is separated into different files. Wordle uses five letter words, so it would be nice to combine them into a single file of 5 letter words.
- Let's start with something easy. How do we read a csv file in Python? Luckily, for us, we have the internet. Do a search of something like "read csv file Python."
import csv # opening the CSV file with open('Giants.csv', mode ='r')as file: # reading the CSV file csvFile = csv.reader(file) # displaying the contents of the CSV file for lines in csvFile: print(lines)
- I tell my students like with any experiment. Don't just follow steps. Try to understand what each step means. You can increase your success in science through planning. In my lab, experiments take 2/3rds planning and 1/3 of dding.
Understanding what each step means
- In doing that, you might do a search for each element.
- Let us open Spyder on Anaconda
- Unzip the folder with all the csv files in it.
- What does import csv mean? The import means to add a plugin to python. The import command is something in computer programming called inheritance where you inherit capabilities that you did not have previously. Python imports functions called modules. You can look it up on the internet, but I would imagine the csv module is to read csv or comma separated format files.
- We are not sure, if we have the Python module. Therefore, in the console, which is on the lower left of Spyder, type import csv.
- Let us make a Python file. File ⇒ New File...
- In Spyder, File ⇒ Save As... and you might name the file 000-WordleHelper.py
- Now type import csv in the file.
- To the right of it, put a comment that describes what it does. While you are learning, I would write it in full sentences like # Import Python module csv, so that I can read csv files.
- File ⇒ Save
- Click the
Type in the rest of the program
# opening the CSV file with open('Giants.csv', mode ='r') as file: # Read a file called Giants.csv and call it file # reading the CSV file csvFile = csv.reader(file) # csv is the module, so csv.reader is the module that can read the file. The csvFile variable are the contents of the csv file. # displaying the contents of the CSV file for line in csvFile: # I changed lines to line because it is reading an individual line. Go through each line. print(line) # Show the line in the console
- Now, click
- Understanding error messages is very important. You will get the following error message:
- The error message is telling you that there is no file called Giants.csv. Look at the code and change Giants.csv to Aword.csv.
- Now, click