运行程序时我的elif语句不起作用

时间:2018-08-06 10:17:37

标签: python

这是一个课程分配代理,可以帮助用户从目录中过滤课程。用户可以选择他们的“主要”,“学期”等标准,这就是为什么我将其保留为elif语句的原因。 Elif在运行时无法正常工作;当用户选择“学期”时,显示“主要”的内容。代码是:

while True:
    print("What kind of courses are you looking for? ")
    Courses = {1: {'Course': 'Interaction Design', 'Major': 'HCD', 'Semester': 'ODD', 'Cycle': '1', 'Level': '1', 'Time': 'AM', 'Days': 'MT', 'Credits': '2', 'Pre-reqesite': 'None'},
        2: {'Course': 'Colour and Texture', 'Major': 'IADP', 'Semester': 'ODD', 'Cycle': '1', 'Level': '1', 'Time': 'AM', 'Days': 'THF', 'Credits': '2', 'Pre-reqesite': 'None'},
        3: {'Course': 'Basics of Service Design', 'Major': 'BSSD', 'Semester': 'ODD', 'Cycle': '2', 'Level': '1', 'Time': 'PM', 'Days': 'THF', 'Credits': '2', 'Pre-reqesite': 'None'},
        4: {'Course': 'Paradoxes & Symbols', 'Major': 'IAIDP', 'Semester': 'EVEN', 'Cycle': '1', 'Level': '1', 'Time': 'PM', 'Days': 'MTTHF', 'Credits': '4', 'Pre-reqesite': 'None'},
        5: {'Course': 'Illustration for Communication', 'Major': 'VC', 'Semester': 'EVEN', 'Cycle': '2', 'Level': '2', 'Time': 'PM', 'Days': 'MT', 'Credits': '2', 'Pre-reqesite': 'None'}}

    print("Here's a list of criteria on the basis of which you can choose your courses: ")
    Criterialist = (["Semester" , "Timings" , "Days", "Major" , "Credits" , "Pre-Requisites"])
    print(Criterialist)
    Criteria = raw_input("Choose any one of the following criteria and I will filter your courses accordingly: ")
    print(Criteria)

    if Criteria == "Major" or "major":
        print("Which of the below-mentioned majors would you like to view courses under?")
        print(Courses[1]['Major'])
        print(Courses[2]['Major'])
        print(Courses[3]['Major'])
        print(Courses[4]['Major'])
        print(Courses[5]['Major'])

        major = raw_input("Please enter your preferred major here: ")
        print(major)
        if major == "HCD":
            print(Courses[1]['Course'])
        elif major == "IADP":
            print(Courses[2]['Course'])
        elif major == "BSSD":
            print(Courses[3]['Course'])
        elif major == "IAIDP":
            print(Courses[4]['Course'])
        elif major == "VC":
            print(Courses[5]['Course'])
        else:
            print("Invalid Entry")
            break

        confirmation = raw_input("Are you interested in choosing from one of these courses? ")
        print(confirmation)
        if confirmation == "yes" or "Yes" or "YES":
            description= raw_input("Would you like to know more about this course for registration? ")
            print(description)
            if description == "Yes" or "yes":
                if major == "HCD":
                    print(Courses[1])
                elif major == "IADP":
                    print(Courses[2])
                elif major == "BSSD":
                    print(Courses[3])
                elif major == "IAIDP":
                    print(Courses[4])
                elif major == "VC":
                    print(Courses[5])
                else:
                    print("Invalid Entry")
                    break
            else:
                print("Maybe you could look at other course criteria?")
        else:
            print("Maybe you could look at other course criteria?")

    elif Criteria == "Semester" or "semester":
        semester = raw_input("Would you like to choose courses for the ODD or the EVEN semester? ")
        print(semester)
        if semester == "ODD" or "odd" or "Odd":
            print(Courses[1]['Course'])
            print(Courses[2]['Course'])
            print(Courses[3]['Course'])

            question = raw_input("Would you like to pick one of the above-mentioned courses? ")
            print(question)
            if question == "yes" or "Yes" or "YES":
                question2 = raw_input("Which course would you like to know more about from this list for selection? ")
                print(question2)
                if question2 == Courses[1]['Course']:
                    print(Courses[1])
                elif question2 == Courses[2]['Course']:
                    print(Courses[2])
                elif question2 == Courses[3]['Course']:
                    print(Courses[3])
                else:
                    print("Invalid data entry!")
                    break
            else:
                print("Maybe you could look at other course criteria?")
                continue


        elif(semester) == "EVEN" or "Even" or "even":
            print(Courses[4]['Course'])
            print(Courses[5]['Course'])
            question = raw_input("Would you like to pick one of the above-mentioned courses? ")
            print(question)
            if question == "yes" or "Yes" or "YES":
                question2 = raw_input("Which course would you like to know more about from this list for selection? ")
                print(question2)
                if question2 == Courses[4]['Course']:
                    print(Courses[4])
                elif question2 == Courses[5]['Course']:
                    print(Courses[5])
                else:
                    print("Invalid data entry!")
                    break
            else:
                print("Maybe you could look at other course criteria?")
                continue

1 个答案:

答案 0 :(得分:5)

if Criteria == "Major" or "major"并没有您认为的那样。 转换为“如果Criteria等于字符串“ Major”,或者字符串“ major”不为空”,这显然总是正确的。

您需要的是if Criteria in ["Major", "major"]: