ErrorMessage says: class myitr, " myitr " is NOT defined

According to my e-book, NumPy contains (1) Arrays(vectors and matrices) (2) common mathematical functions like “cos” and “sqrt”
(3) Generating random numbers (4) Linear algebra, etc.
Does etc. contain class " myitr " ? Can any experts tell me the truth?

Rather than posting screenshots, which are inaccessible for those using screen readers and just generally hard to deal with, it’s better to use the code formatting options in this forum. The <\> button will format selected text as a code block.

In this case, it looks like you have an indentation error: your for loop is inside the class definition.


Roger. I will strictly follow your rule. Sorry about that.

I do follow your advice by putting the for loop to the extreme left, however, ErrorMessages persist
" NameError: name ‘upper’ is not defined ". Any solution?

Which line is raising that exception? What’s on that line? Do you see upper?

1 Like

Again, please post your current failing code, inline using the </>
button. Otherwise we are just guessing about what you’re doing.

Cameron Simpson

You have to be more careful with what you are typing. In the def __init__() method,
in the header, you have upper_limit, as a parameter. Yet, in the body, you have upper.limit
as an assignment value.



Barnett: I see upper in 2 places, (1) def init(self, upper_limit=5): (2) self.limit = upper.limit

Exactly. The first is part of a name and the second is a name in its own right. Not the same thing.

1 Like

Indeed. But what is the solution? In my e-book,
there’s no problem “myitr” is NOT defined.
Anything wrong with the kernel of my laptop

@onePythonUser has already posted the solution.

1 Like

I think that you should do what @jamestwebber stated about typing your code as opposed to just pasting the screenshot.

Copy your code. Then paste it in between two lines each containing three wavy apostrophes.
They are located just below the escape key. You have to press shift in tandem for them to appear.

1 ~~~
paste here

  1. Please make sure the code is properly indented where appropriate.
  2. Please make sure that name references match name assignments, including upper/lower case.

Paul, again, you come to my rescue and the problem solved. Thaniks.
Can you turn your attention to the trickier one
" Would a shade of difference in shape of Mixins ruin the result of a programm --------- ? " Thanks.

The problem has nothing to do with NumPy, and there is no good reason to expect it to have anything to do with NumPy, and there is nothing in the code you have shown that uses NumPy or would benefit from NumPy.

It does not make sense to try to find out about whether NumPy includes something called myitr, because the point of your own code is to define that. When you write class myitr:, that’s what it means.

The problem is caused because of indentation. Because of how you indented the code, the loop for i in myitr(5): is inside the class. This makes no sense. Python needs to understand what a class myitr: is first, before it can run such a loop. Therefore, that loop cannot be part of the definition.

You get NameError because, when Python figures out what class myitr: contains, it tries to run the for i in myitr(5): loop, which means it has to look up myitr to find out that it is a class. But myitr is not yet a class, because Python did not finish creating it yet.

This loop doesn’t do anything necessary for defining the class; it only uses the class. Therefore, it should be outside of the class, which means it should not be indented into the class body.

In the previous thread, you had the same problem with indentation (actually, the wrongly indented code was indented even further). Then there were several problems in a row that were all the same: using the wrong name, because of wrong capitalization.

You were also told more than once in that thread (I don’t know what happened to @hansgeunsmeyer 's post) to post the code properly as text, so that we can discuss it properly. You agreed to do so, but then made this thread and are still posting the code as images - so you’ve been told about it in this thread again. Please read the pinned thread and make sure you understand how this works.

My advice to you is that if you are getting stuck on issues like this, you should not be trying to follow this e-book. Instead, you should be practicing with a general tutorial for the fundamentals of Python. The official documentation includes one and there is more advice on the Python web site. Please keep in mind that learning to program - in Python or any other language - is a process of making mistakes and learning from them. It is about paying attention and trying to solve problems yourself using what you have already learned (instead of asking others about every issue that comes up).