May-01-2019, 10:52 PM
I'm not entirely sure if this is what your looking for and it can probably be improved upon.
class ChoiceError(Exception): pass class RestartChoices(): def __init__(self): self.reset_choices() def reset_choices(self): self.choices = ["Start Now", "5 minutes", "2 hours", "4 hours", "8 hours"] self.last_choice = '' def make_choice(self, choice): if choice not in self.choices: raise ChoiceError('invalid choice') self.last_choice = choice if choice == self.choices[-1] or choice == self.choices[0]: self.choices = [] return choice_index = self.choices.index(choice) + 1 self.choices = self.choices[:1] + self.choices[choice_index:] restart_choices = RestartChoices() restart_choices.make_choice('5 minutes') print(f'choice: {restart_choices.last_choice}') print(f'Remaining: {restart_choices.choices}') restart_choices.make_choice('4 hours') print(f'choice: {restart_choices.last_choice}') print(f'Remaining: {restart_choices.choices}') restart_choices.make_choice('8 hours') print(f'choice: {restart_choices.last_choice}') print(f'Remaining: {restart_choices.choices}') restart_choices.reset_choices() restart_choices.make_choice('2 hours') print(f'choice: {restart_choices.last_choice}') print(f'Remaining: {restart_choices.choices}') restart_choices.reset_choices() restart_choices.make_choice('Start Now') print(f'choice: {restart_choices.last_choice}') print(f'Remaining: {restart_choices.choices}')
Output:choice: 5 minutes
Remaining: ['Start Now', '2 hours', '4 hours', '8 hours']
choice: 4 hours
Remaining: ['Start Now', '8 hours']
choice: 8 hours
Remaining: []
choice: 2 hours
Remaining: ['Start Now', '4 hours', '8 hours']
choice: Start Now
Remaining: []