Skip to content
cmɢʟee edited this page Mar 1, 2022 · 8 revisions
Pyordle on Pydroid 3

Learn Python with Pyordle!

Pyordle is a Python 3 implementation of a popular online word game in 2022. It is for teaching Python basics and is thus not of professional code quality. The basic version is text-only; optional enhancements include a graphical user interface, and a solver to automatically solve similar puzzles or give hints to the player.

Links

Required files

Game implementations

Python interpreters

  • Online: online-python – must open pyordle_answers.txt and pyordle_valid.txt as tabs, no tkinter
  • Online: onlinegdb – must open pyordle_answers.txt and pyordle_valid.txt as tabs, broken tkinter
  • Windows: single-file Python interpreter – no tkinter
  • Android: Pydroid 3 – cannot call with command-line arguments, contains ads

Agenda

Intro

  • about me
  • about this course
  • tell us your
    • name
    • programming experience
    • what you hope to get from this course
  • about Python
    • Python 2 vs 3 (print, input, strings, /, names of things etc)
  • set up Python
Pyordle on Notepad++ NppExec

Basics

  • print
  • simple variables
    • naming conventions
    • int
    • float
    • bool
  • strings
    • multiline strings
    • extracting characters
    • lower, upper
  • operators
    • precedence
    • /
  • shortcut operators (e.g. +=)
  • input vs raw_input
  • .format vs %
  • multiline commands (\)
  • multicommand lines (;)
  • comments
  • indentation
  • functions
    • default parameters
    • return
    • global

Exercise 1: Have a go at exercise 1 in the sidebar!

Pyordle in hint mode on Linux

Simple multi-element datatypes

  • list
  • tuple
  • set
  • dict
  • list comprehension
  • len
  • range
  • join
  • extracting elements
    • reversing a list

Handling local files

  • reading files
  • writing files

Exercise 2: Read word lists into sets

Flow control

  • if, elif, else
  • while
  • for
    • enumerate
    • items, keys, values
  • break
  • continue

Exercise 3: Input valid guesses

More I/O

  • command-line parameters
  • Web access
Pyordle in solver mode on Linux

Exercise 4: Think up an algorithm to evaluate players' guesses

More advanced stuff

  • sorted
  • lambda

Exercise 5: Display the results and end-game messages

Not covered

  • object-oriented (class)
  • exceptions
  • multithreading
  • regular expressions
  • specific applications
    • advanced games (Pygame, PyOpenGL)
    • numerical computing and statistics (numpy, scipy)
    • imaging (PIL, OpenCV)
    • machine learning (PyTorch, TensorFlow)

The "Solution template" link above gives an outline of the text-only game. Comments marked TODO: and ... are to be completed by the learner.

In exercise 1,

  • try to understand the workflow
  • implement display_message to print a newline followed by the message given
  • randomly pick a word from answer_s as answer

For exercise 2,

As exercise 3,

  • implement input_guess to accept a valid guess from the player

In exercise 4,

  • implement evaluate_guess to populate guess_mark_l with the correct "colours"

For exercise 5,

  • implement display_result to tell the user the result
  • display appropriate message when a game ends

As optional exercises,

  • implement a hint mode to suggest possible words to the player
  • implement a demo mode to let the computer play itself
  • implement a solver mode to let the computer solve a third-party puzzle
  • implement a graphical user interface using tkinter

The modes can be either read from a command-line argument or hardcoded.

If your environment does not support reading local files, such as some online interpreters, below is a version with the word lists compressed and encoded into the Python script under the comment ## Read words (how it works is beyond the scope of this course!)

Clone this wiki locally