Testing English Wordle

Jed Rembold & Fred Agbo

September 25, 2023

Announcements

  • Problem set 3 is due tomorrow at 12:noon
  • I am working on returning PS 2. Apologies for the few remaining
  • First project will be posted tomorrow, will be due on October 3rd
  • Polling continues today! Remember to use this link https://www.polleverywhere.com/agbofred203 when it becomes active

Formatting Strings

  • F-strings allow us to easily substitute in values, but what if we want those values to have a particular format?
    • Rounded to the nearest two decimal places, for example
  • One option would be to handle all this before the substitution manually
  • Python gives a more streamlined method, using a format spec
  • A format spec will be given inside the {} placeholder
    • Comes after the variable/value itself
    • There is a colon between the variable/value and the format spec
    A = 10.234
    print(f"The value of A is {A:0.2f}")

Shaping your format

  • A Format spec is a special string that determine the desired format
  • Lots we can do, but we rarely need to do it all at once
  • The basic building blocks (square brackets just to group):

    [[fill]align][sign][width][,][.precision][type]

  • Type
    • How you want the object represented as a string
    • “d” - base-10 integer
    • “f” - float or decimal
    • “e” - scientific notation
    • More on next slide
  • Precision
    • How many digits to display after a decimal point
    • Details can vary a little by conversion type
  • Grouping?
    • A comma here indicates that numbers should be grouped in sets of 3 and separated with a comma
  • Width
    • The minimum number of characters you want the formatted value to have
    • If not otherwise specified, pads the value with space characters
  • Sign?
    • If the sign of the number should be specified
    • A + sign ensures all numbers will have either a + or - sign in front
    • A space just adds a space before positive numbers (negatives would have a - sign in front)
  • Fill and Align
    • How you want the text aligned if it is shorter than the minium width
      • Can be <, >, or ^ for left, right, or center justified
    • Any fill characters you want to fill the empty space come before
      • Default is space

Review Question!

Which of the provided formatted string options below would evaluate to appear as:

**101,234.98 & 4000

when printed?

  1. f"{101234.984:*<12,.2f} & {3200//8:1<4d}"
  2. f"{101234.984:*>12,.2f} & {32000//8:1>3d}"
  3. f"{101234.984:*<12,f} & {320//8:1>4d}"
  4. f"{101234.984:*<12,.2f} & {32//8:1<4d}"

Learning English

  • When working with sequences of characters, it is often useful or desirable to determine if they form actual valid English words
  • This class provides for you a new library, through the file english.py
  • The english library provides two objects you can import into your programs:
    • The constant ENGLISH_WORDS, which is a list of all the valid words in the English dictionary
    • The function is_english_word(), which accepts a single string as an argument and returns True if the string represents a valid English word.
  • This library will be particularly useful for Wordle!

Example: How many 2 letter words?

  • Before we start writing code, let’s pause. Give a physical English dictionary, how could you go about figuring out the number of two letter words?
from english import ENGLISH_WORDS

count = 0
for word in ENGLISH_WORDS:
    if len(word) == 2:
        count += 1
print(count)
from english import is_english_word

count = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for letter1 in alphabet:
    for letter2 in alphabet:
        word = letter1 + letter2
        if is_english_word(word):
            count += 1
print(count)

Introduction to Wordle

  • Our first project will be Wordle
  • Milestone guide will be posted tomorrow
  • Not due until October 3rd
The game of Wordle

Your Responsibilities

  • We will provide you with a custom data type that will handle all the graphics and user interaction
    • Don’t worry, you’ll have a chance to implement your own GUIs later in the semester!
  • Your responsibilities will include:
    • Displaying and reading letters from boxes
    • Evaluating whether a word is valid
    • Determining what color each letter of a word should be
    • Determining when victory or defeat occurs

Your Toolbox

  • Special functions provided by the provided graphics data type: WordleGWindow
    • These will be well documented, and include, but are not limited to, things like
      • Getting or setting a letter in a particular box
      • Getting or changing the color of a given box
      • Changing which row is used when characters are entered
  • Variables and functions
  • Control statements
    • Good use of loops and if statements will be very useful
  • Basic string functions

Receiver Syntax

  • So far, all operations between or on objects have used symbols to indicate the operation

    • The + sign, for instance
  • Going forward, we will begin to see more examples of operations on objects that use receiver syntax

  • In receiver syntax, we specify the object to act on, followed by a dot and then a predefined function (called a method here) name

    obj.method_name()
    • This is like you are running this special function on the object, so you need the () at the end
    • Some methods also allow arguments, to influence exactly how the operation will proceed

An Approach to Success

  • Each project is accompanied by a highly detailed guide: read it!
    • Explains background ideas so that you can understand the big picture of what you are needing to do
    • Also included a breakdown of individual milestones
      • A milestone is a discrete checkpoint that you should ensure is working (and that you understand!) before moving on
  • Projects are all about managing complexity. If you start trying to implement milestones out of order, you are asking for disaster
  • Don’t let yourself get overwhelmed by scale. Focus on one particular milestone at a time, which should involve focusing only on a small part of your overall code
// reveal.js plugins