执行while循环后,我的程序无法返回预期结果

时间:2019-01-17 21:32:46

标签: python-3.x class

我的程序在产生所需结果之前会重复执行。我希望它只执行一次

如果while循环条件为true,我希望我的程序从一个类移动到另一个类,而是在给出所需结果之前,它继续重复执行循环

class Child(Stages):

def enter(self):
    print(dedent("""
                    %s, Understanding your child's unique developmental progress is necessary
                    in order to interpret, accept or adapt to the society
                    (as well as your own behaviour). """)% user_name)

    print(dedent("""
                    Not many children are as well behave as you are %s \n
                    Tell us a few of your good behaviors
                """)% user_name)
    c_gud_list = ["a","b","c","d"]
    cgudbehave = input("Good behaviour: ")
    c_behave_reply.append(cgudbehave)
    count = 1

    while count < 3 and cgudbehave in c_gud_list:
        cgudbehave = input("Another good behaviour: ")
        c_behave_reply.append(cgudbehave)
        count += 1

        if cgudbehave in c_gud_list and count == 3:

            for i in c_behave_reply:
                print(i)
            return 'teenager'

        elif count < 3 and cgudbehave not in c_gud_list:
            print("%s, Don't tell me you forgot ur own good behaviours.\n Try all over" % user_name)
            return 'child'
        else:
            pass
    else:
        return 'teenager'

class Teenager(Stages):

    def enter(self):
        print("Welcome %s. You have grown since the last time we met" %user_name)

在此条件成立后,我希望程序移至“少年”类 elif计数<3,并且cgudbehave不在c_gud_list 中,并且“ Child”类仅执行一次,不超过一次

0 个答案:

没有答案