[Python] why using conditions in incapsulation gives the same result [duplicate]

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    based on your response to a situation using conditions, you access different functions in class as a training to use incapsulation .

    import random
    class Character:

    def __init__(self):
    stuff = ["lunch", "bag", "money", "phone"]
    self.__obj=random.choice(stuff)

    def timid_person(self):
    print('im sorry could you please return my '+ self.__obj)

    def bully_person(self):
    print('give me that'+ self.__obj + 'or ill break your head')

    def nice_person(self):
    print('you cant have my' + self.__obj)

    act1=Character()
    scene=input("someone is trying to rob you what is your response:")
    if "sorry" or "please" in scene:
    print(act1.timid_person())
    elif "beat" or "break" in scene:
    print(act1.bully_person())
    else:
    print(act1.nice_person())


    the problem is that it only returns the function of timid_person.

    Continue reading...

Compartilhe esta Página