I am trying to figure out how to have a user input the index number of an object in a list. My ultimate goal is to show a list of the spells in your spell book sorted by index number. I then want the user to be able to input the index number to choose the spell and perform a function with it. Here is a simple example:
(The spells are objects)
spells = [spell1(), spell2()]
print(spells.index(Spell),Spell.name)
Should show:
0 spell1
1 spell2
x = input('Input number of spell')
print(spells[int(x)].description)
So, by inputting the index number of the object in the list I retrieved its description. I have gotten the function itself to work. However, I am having difficulty setting up rules so that it does not accept any input other than the available indexes in the list. In this example, only 0 and 1 should be available inputs. I also wanted the option of 'p' to go back to the previous screen.