0

What is the error in this program?

While writing this program in python for my school exam, I encountered a Syntax error while trying to run it. I am not great at coding, and I need to find the error. Here's the code: #Initialization count1=0;count2=0;Stuname=0;Stunames=[];Sub1Choice=0;Sub2Choice=0;Sub1Choices=[];Sub2Choices=[];Sub1Position=[];Sub2Position=[];SubNo=[] Sub1Group=[];Sub2Group=[];SpareNo=0;UnallocatedNo=0;SubNames=["Phy","Chem","Hist","Geo","CS"] SubCount=[0,0,0,0,0] #Initilaized so I can increment the the SubCount for that subject by referring to them as a variable. (for example, SubNCount[1]=SubCount[1]+1) #Task 1 for count1 in range(60): Stuname=input("Enter the student's name: ")#raw_input does not exist in python 3, all variables are strings by default. Stunames.append(Stuname) print(" The numbers for the 5 subject choices are: Physics=1, Chemistry=2, History=3, Geology=4, Computer Science=5") Sub1Choice=input("Enter the number of your first selected subject: ") while(int(Sub1Choice)<1)or(int(Sub1Choice)>5):#int has to be used in order to refer to the variable as a integer as by default it is a string Sub1Choice=input("Please enter a valid option, between 1 to 5: ") Sub1Choices.append(SubNames[Sub1Choice-1]#Sub1Choice-1 in order to refer to the correct index number SubCount[int(Sub1Choice)-1]=SubCount[int(Sub1Choice)-1]+1

13th Feb 2018, 1:55 PM
Neel Reddy
Neel Reddy - avatar
1 Odpowiedź
0
maybe store subchoice in integer variable before using it as indexer since input default is str even if you input a number. Sub1Choice = int(Sub1Choice)
13th Feb 2018, 3:45 PM
Markus Kaleton
Markus Kaleton - avatar