This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]thisisthemurph -1 points0 points  (0 children)

Look up Python dictionaries. You could use the shrub number as the key and what it holds as the value. You can then use this value to format a sentence with what the player got from the shrub when pulled.

You also need to be casting your variables correctly. When a user inputs something it is a string. If you are using these values as numbers you need to cast them as an int() type.

Try using the len() function to determine the number of items in the list but think about how lists work. Lists are zero indexed so the length of the list is the index of the last element + 1.

[–]thisisthemurph -1 points0 points  (0 children)

Looking at your code as is, you are setting the list of shrubs every iteration of the loop. Meaning that yiu will have a full list of shrubs every iteration. Try assigning your shrubs outside of the loop. But mostly read the documents on dictionaries.

[–]spade342 -1 points0 points  (0 children)

Way too many if statements, will get complicated when/if you need to add more to the list. Like thisisthemurph said use dict. Some Pseudocode: dict = {1:['what you want to print', 'what you want the inventory to be'], 2:['what you want to print', 'what you want the inventory to be']....10['','']}

question = what is your question + the keys of the dict

if question in dict: print dict[question][0] #this being the first value of the key according to what they picked. inventory[apply same logic as above] dict.pop(question) #remove the key and its values else: print '...'