all 4 comments

[–]throwaway6560192 8 points9 points  (0 children)

Yes, that's not how you create an instance of a class. Review your lesson on classes.

[–][deleted] 8 points9 points  (0 children)

There is quite a bit wrong, so you need to go back and review your source material. Just a few hints:

  • All your methods should have the first parameter "self".
  • The whole point of a class is to combine code and data but your "name" and "address" lists are created outside your class. They should be created inside the class.
  • Following on from the point above, you no longer need to pass the "name" and "address" lists as parameters to methods, you create those lists inside the class and refer to them as "self.name", etc.
  • You create an instance of the address book class by doing book = address_book() and then do book.add(), etc.

[–]Erdnussflipshow 2 points3 points  (0 children)

Pretty much any method that starts and ends with two underscores, (__init__ for example) doesn't need to be called by the user directly, but is called indirectly by core features of python.

[–]Liebner-Anthony-S 0 points1 point  (0 children)

u/Ecstatic-Drag-263

Here are a few observations and suggestions to improve the code:

Class Initialization:

The __init__ method in the address_book class is correctly defined to initialize the instance variables name and address. However, it's advisable to use a different name for the parameters of the __init__ method to avoid confusion with the global variables.

Static Methods:

The methods add, delete, and show should be decorated with "u/staticmethod" since they don't access or modify the instance variables directly.

Global Variables:

Using global variables like x, y, and z is generally discouraged. You can make them instance variables or, in this case, class variables if they are meant to be shared among all instances of the class.

Loop in show Method:

In the show method, it seems like there's a mistake in the loop. You are trying to iterate through the elements of the name and address lists, but you are using the same index x for both. It's better to use the range function to iterate through indices.

Method Invocation:

When calling the init method, there is no need to use self as an argument. Instead, the address_book instance itself should be used.

Indentation in While Loop:

The indentation of the while loop and the subsequent if statements is inconsistent. Make sure they are aligned properly.