Wordle Helping Program

From PharmWiki
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.
  1. 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.
  2. 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.
  3. 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

import csv

  • In doing that, you might do a search for each element.
  1. Let us open Spyder on Anaconda
  2. Unzip the folder with all the csv files in it.
  3. 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.
  4. 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.
    1. If you get no errors, that means that the module is installed, it should look like: Wordle001.pngClick to enlarge
    2. If you do get errors, that means that the module is not installed, in the console type: !pip install csv
  5. Let us make a Python file. File ⇒ New File...
  6. In Spyder, File ⇒ Save As... and you might name the file 000-WordleHelper.py
    1. The 000 is to make sure that it is on the top of the file list.
    2. Put the file in the same directory as the csv files. If you did it correctly, it should look like this:Wordle002.pngClick to enlarge
    3. The Spyder program should look like: Wordle003.pngClick to enlarge
  7. Now type import csv in the file.
    1. If you did it correctly, it should look like: Wordle004.pngClick to enlarge
  8. 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.
    1. If you did it correctly, it should look like: Wordle005.pngClick to enlarge
  9. File ⇒ Save
  10. Click the Wordle006.png

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
  • If you did it correctly, the output should look like this: Wordle007.pngClick to enlarge
  1. Now, click Wordle006.png
  2. Understanding error messages is very important. You will get the following error message: Wordle008.png
  3. 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.
    1. If you did it correctly, the output should look like this: Wordle009.pngClick to enlarge
  4. Now, click Wordle006.png
    1. If you did it correctly, it should look like this: Wordle10.pngClick to enlarge