My Python program compiles long enough to take input, but won't process the input

def funcName():

Storing inputs for the user’s favourite subjects.

    in0 = input("Type your first favourite subject.")
    in1 = input("Type your second favourite subject.")
    in2 = input("Type your third favourite subject.")

    favSubjects = ['Physics', 'Computer_Science', 'Lunch']

Creating list of user’s favourite subjects.

    favSubjects2 = []

Storing user’s favourite subjects.

    favSubjects2[0] = in0
    favSubjects2[1] = in1
    favSubjects2[2] = in2

Comparing program’s subjects with the user’s.

    if(favSubjects[0] == favSubjects2[0] or favSubjects[0] == favSubjects2[1] or favSubjects[0] == favSubjects2[2]):
    elif(favSubjects[1] == favSubjects2[0] or favSubjects[1] == favSubjects2[1] or favSubjects[1] == favSubjects2[2]):
    elif(favSubjects[2] == favSubjects2[0] or favSubjects[2] == favSubjects2[1] or favSubjects[2] == favSubjects2[2]):

def main():




  1. CoryKramer
    0 Votes

    This will produce an IndexError as you cannot assign to indices that do not yet exist

    favSubjects2 = []
    favSubjects2[0] = in0
    favSubjects2[1] = in1
    favSubjects2[2] = in2

    To store these items in your list you should use the following

    favSubjects2 = [in0, in1, in2]
Please signup or login to answer this question.

Signup for an account and start participating in our site today!

Social Signup

You can also login with your Facebook, Twitter or Linkedin account

Log in with Facebook