I'm having a problem with a try except
within a while
loop. I'm still relatively new to programming and this is part of my A2 Comp4 project.
def CheckValidInitials(initials):
CheckIfTrue = False
Count = 1
while CheckIfTrue == False:
while len(initials) == int(3) or len(initials) == int(4):
listInitials = list(initials)
print(len(initials))
while len(listInitials) - Count >= 0:
print(len(initials))
print(len(listInitials) - Count)
Count = Count + 1
print(listInitials)
try:
int(listInitials[Count])
except IndexError and ValueError:
CheckIfTrue = True
else:
print("One of your initials is a number, this is not valid")
print()
Count = 1
initials = input("Please enter valid initials: ")
listInitials = list(initials)
else:
initials = input("Please enter valid initials: ")
return initials
I keep getting this error:
File "D:\A2 Computing\Comp4\Prototype\Prototype Mk 3\TeacherInfo.py", line 105, in CheckValidInitials
int(listInitials[Count])
IndexError: list index out of range
My problem with this is that I thought I excepted IndexError
's in my try except
. It is supposed to be throwing up this problem.
The overall code is supposed to be checking whether initials (entered in another function) contain any numbers.