Help Needed With Ex 41 - ValueError

Thanks in advance - I am hoping someone can help me with LPHW3 Ex 41 I am unable to debug this code. I receive the following error after copying and pasting the code from the book and then trying to run it:

Traceback (most recent call last):
File “”, line 81, in
question, answer = convert(snippet, phrase)
ValueError: not enough values to unpack (expected 2, got 0)
PS C:\Users\sinua\OneDrive\Documents\Data_Science_Coding\python_hardway_3>

This is the code I am running which is exactly the same as in the book:

import random
from urllib.request import urlopen
import sys

WORDS = []

        "class %%%(%%%):":
            "Make a class named %%% that is-a %%%.",
        "class %%%(object):\n\tdef __init__(self, ***)" :
            "class %%% has-a __init__ that takes self and *** params.",
        "class %%%(object):\n\tdef ***(self, @@@)":
            "class %%% has-a function *** that takes self and @@@ params.",
        "*** = %%%()":
            "Set *** to an instance of class %%%.",
            "From *** get the *** function, call it with params self, @@@.",
        "***.*** = '***'":
            "From *** get the *** attribute and set it to '***'."

# do they want to drill phrases first
if len(sys.argv) == 2 and sys.argv[1] == "english":
    PHRASE_FIRST = False

# load up the words from the website
for word in urlopen(WORD_URL).readlines():
    WORDS.append(str(word.strip(), encoding="utf-8"))

def convert(snippet, phrase):
    class_names = [w.capitalize() for w in
                  random.sample(WORDS, snippet.count("%%%"))]
    other_names = random.sample(WORDS, snippet.count("***"))
    results = []
    param_names = []

    for i in range(0, snippet.count("@@@")):
        param_count = random.randint(1,3)
        param_names.append(', '.join(
            random.sample(WORDS, param_count)))

    for sentence in snippet, phrase:
        result = sentence[:]

# fake class names
    for word in class_names:
        result = result.replace("%%%", word, 1)

# fake other names
    for word in other_names:
        result = result.replace("***", word, 1)

# fake parameter lists
    for word in param_names:
        result = result.replace("@@@", word, 1)


    return results

# keep going until they hit CTRL-D
    while True:  
        snippets = list(PHRASES.keys())

        for snippet in snippets:
           phrase = PHRASES[snippet]
           question, answer = convert(snippet, phrase)
           if PHRASE_FIRST:
               question, answer = answer, question

           input("> ")
           print(f"ANSWER: {answer}\n\n")
except EOFError:

Your file is actually very different, and it’s all about the spacing. Remember that python uses indentation to figure out where code belongs, so yours is off in that regard. It can be difficult to see it, so do this:

  1. Get my version of the file here
  2. Use either this online tool or use the command line tool diff to see the difference.
  3. Your text editor also most likely will have this diff tool so check the docs for it.
  4. Go through each line that’s shown as different and make it exactly the same.

Or, you can just use my version of the file.

Yes, my version was indeed VERY different and now has been fixed. Thank you for helping and sharing the tools for identifying the differences. This reinforced the importance of developing the skill to notice details in code,which you emphasize in the book and videos. Thanks again!

The thing to remember is you have to always assume you’re wrong. That’s really difficult for most people because they’re used to trusting their brain and assuming it’s telling them the truth. Programming (and actually painting) shows you that, nope, your brain lies to you constantly, usually be summarizing details as it thinks they’re not important. The number of spaces at the the beginning of a line of code is a good example of something your brain just skips over as pointless, but it’s very important.

Another example is how you probably didn’t catch that I typed “the” twice in that last paragraph.

A free service run by Zed A. Shaw for