1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] PYTHON_CLASS AND METHODS

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    Goal: Learn to instantiate objects and call methods.

    Assignment: The class HairConditioner supports the following methods:


    • squeezeOut: takes no arguments, and squeezes out the conditioner;


    • condition: takes a single string argument, and conditions the thoughts of the subject using the product.

    Assume the variable conditioner stores a reference to a HairConditioner object.

    Write some code that squeezes conditioner, and conditions with the message "Remember to turn down the thermostat when you go to sleep".

    THIS IS WHAT I TRIED:

    class HairConditioner:
    def __init__(self):
    self.__called_squeeze_out = False
    def squeezeOut(self):
    print("Squeeze out")
    self.__called_squeeze_out = True
    def called_condition(self, subject):
    print(f"Conditions the thoughts of the subject using the product {subject}")

    prototype284 = HairConditioner()
    prototype284.squeezeOut()
    called_squeeze_out = getattr(prototype284, "_HairConditioner__called_squeeze_out", None)
    print(f"Called attribute value: {called_squeeze_out}")
    prototype284.called_condition("Hello World")


    AND THIS IS THE ERROR:

    AttributeError: 'HairConditioner' object has no attribute '_HairConditioner__called_condition'. Did you mean: '_HairConditioner__called_squeeze_out'?


    EVEN AFTER I CHANGED THE ATTRIBUTE THEN IT STILL SAYS I AM WRONG

    Continue reading...

Compartilhe esta Página