[Python] How to pass in my meat, rice and beans value, from my Burrito class to the meat...

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have four classes, I am trying to pass in my meat value, rice value and beans value to their respective classes, and return their value through the Burrito class. I have battled with this for two days but no visible progress, any idea on what to do, apologies for any grammatical error. Below is the first three classes, According to the instructions given am not suppose to touch any line in the first three classes, all my code modifications should be in the Burrito class.

    class Meat:
    def __init__(self, value=False):
    self.set_value(value)

    def get_value(self):
    return self.value

    def set_value(self, value):
    if value in ["chicken", "pork", "steak", "tofu"]:
    self.value = value
    else:
    self.value = False

    class Rice:
    def __init__(self, value=False):
    self.set_value(value)

    def get_value(self):
    return self.value

    def set_value(self, value):
    if value in ["brown", "white"]:
    self.value = value
    else:
    self.value = False

    class Beans:
    def __init__(self, value=False):
    self.set_value(value)

    def get_value(self):
    return self.value

    def set_value(self, value):
    if value in ["black", "pinto"]:
    self.value = value
    else:
    self.value = False


    Here is the class were am suppose to pass in value from and return value from as well.

    class Burrito:
    def __init__ (self, meat, to_go, rice, beans):
    self.meat = Meat(meat)
    self.set_to_go(to_go)
    self.rice = Rice(rice)
    self.beans = Beans(beans)

    def set_meat(self, meat):
    self.set_value(meat)

    def set_to_go(self, to_go):
    to_go_list = [True, False]
    if to_go in to_go_list:
    self.to_go = to_go
    else:
    self.to_go = False

    def set_rice(self, rice):
    self.set_value(rice)

    def set_beans(self, beans):
    self.set_value(beans)

    def get_meat(self):
    self.meat_v = Meat()
    return self.meat_v.value

    def get_to_go(self):
    return self.to_go

    def get_rice(self):
    self.rice_v = Rice()
    return self.rice_v.value

    def get_beans(self):
    self.beans_v = Beans()
    return self.beans_v.value


    Here is the line am using to test my code:

    newburrito = Burrito("pork", True, "brown", "pinto")
    print (newburrito.meat)


    This is the error line am getting:

    <__main__.Meat object at 0x7fa5ad8bccf8>


    Am expecting it to print

    pork

    Continue reading...

Compartilhe esta Página