Home > Back-end >  Please I need a dress c0de
Please I need a dress c0de

Time:10-11

I'm dealing with classes in python and I'm trying to create a dress code for a Dev by calling a function init_vibe_check. The output is showing me an error that init_vibe_check is not defined, and it is right there before the function create_dress_code_for. Please help!

Raw Code:

#
#  15:03 : October 8, 2021
#  By: Your friendly neighborhood SWE ==> ADMINIXTRATOR
#  AIM: Keep world peace by creating a dress code
#

class Dev:
    level = 'Pre-Senior';

    def __init__(self, name, has_vibe):
        self.name = name;   
        self.has_vibe = has_vibe;

class PeaceKeeper:

    def __init__(self, dev):
        super().__init__();
        self.dev = dev;

    def init_vibe_check(self):
        if self.has_vibe == True:
            return True;
        else: return False;

    def create_dress_code_for(self):
        he_will_receive_props = init_vibe_check(self);

        if he_will_receive_props == True:
            print("Hi "   self.name   ", you are entitled to a dress code");
        else: 
            print(self.name   ", you cannot get a dress code");


# Create two sample Devs
david_chuka = Dev("David Chuka", True);
haks = Dev("Haksoat", False);

# Keep world peace
PeaceKeeper.create_dress_code_for(david_chuka);
PeaceKeeper.create_dress_code_for(haks);

Screenshot:

enter image description here

CodePudding user response:

The syntax for calling class methods is not super intuitive. You should be doing this:

he_will_receive_props = self.init_vibe_check()

Instead of this:

he_will_receive_props = init_vibe_check(self);

(Also note that semicolons are unnecessary in python, they are ignored by the interpreter for the benefit of programmers used to using them)

CodePudding user response:

I'd presume that the class variable level is not true for the attributes passed to the class. It is impossible for David Chuka and Haksoat to be pre-senior.

These are primordial beings in the preliminary essence of life and should be moved up in the hierarchy to prevent an absolute loss sublimity.

Secondly, dress codes for devs are unreal. They eliminate boredom and reduce tension; accentuating interest and inducing curiosity which has killed countless cats.

Life should be kept simple with a singleton and pulmonary object, left to dwell in absolute sync with Rust ownership system.

I hope this helps. Read through and rework your code philosophy to fit into these words and all of humanity shall prevail over and over again!

May the force be with you!

  • Related