I'm currently learning how to program in Python (3.8) and I've had a problem with a function in my budget tracker program. The except clause isn't executing when i type other thing then 'Day','Week','two weeks','three weeks','Month','three months','half a year','Year','two years','five years' it just continues and keep going saying 'When do you get net money?' when i type 'Day','Week'... it breaks but I want that the except clause execute when an error occurs. Thank you in advance for answering my question and making my function more efficient. If you know how to make better function to ask 'When do you get net money?' write it. Sorry if I type something wrong here, my English isn't perfect.
class Main:
def __init__(self):
self.income_phase = ''
def income_phase_ask(self):
while self.income_phase not in ['Day','Week','two weeks','three weeks','Month','three months','half a year','Year','two years','five years']:
try:
self.income_phase = input('When do you get net money? (Day; Week; two weeks; three weeks; Month; three months; half a year; Year; two years; piec lat): ')
except Exception:
print('Error! Try again!')
a = ('valid', 'inputs')andif self.income_phase not in a: raise ValueError()to trigger the except block.