Python unindent does not match any outer indentation level error.

Asked 2 years ago, Updated 2 years ago, 70 views

import random as rd


                   class Vocabulary:

                        def __init__(self, wdict):

                            self.words = wdict.copy()
                            self.untrained = set(self.words)
                            self.renew()

                        def renew(self):

                            self.target = list(self.untrained)
                            rd.shuffle(self.target)
                            self.untrained = set()

                        def target_keys(self):

                            return self.target

                        def check(self, key, value=None):

                            if key not in self.words:

                                return None

                            if value is not None:

                                if self.words[key] == value:

                                    return Ellipsis

                                self.untrained.add[key]

                            return self.words[key]

                        def shuffle(self):

                            rd.shuffle(self.target)

                    wdict = {}

                    while True:

                        line = input ("the spelling and meaning of the word to be registered/memorized: ")

                        tokens = line.split()

                        if len(tokens) != 2 :

                            break

                        wdict[tokens[1]] = tokens[0]

                    voc = Vocabulary(wdict)

                    while len(voc.target_keys()) > 0:

                        print("\nWords to memorize:", voc.target_keys())

                        nQNA = int (input ("number of questions and answers by word: ")))

                        print()

                        for index in range(0, nQNA):

                            voc.shuffle()

                            for meaning in voc.target_keys():

                                Which word means answer = input("" + meaning + ""? ")

                                word = voc.check(meaning, answer)

                                if word is Ellipsis:
                                    print ("Correct")

                                else:
                                    print ("The answer is ' + word + '")

                        voc.renew()

                    print("\nWord learning is over.")

I wrote the source code exactly as it was in the book, but from the wdict={} part, the error 'unindent does not match any outer indication level' appears continuously. I think it's an indentation problem, but I wrote it exactly as it was in the book, but why do I keep getting this error?

Aside from having a lot of problems with the textbook, how can I fix it? I'd really appreciate your help!

python error indentation

2022-09-20 16:21

1 Answers

Make sure that spaces and tabs are not used interchangeably, and that the indentation by syntax is consistent.


2022-09-20 16:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.