This is most likely a very basic question as I just started Python the other day, but I couldn't find any documentation. I'm practising with a basic text-adventure program.
Here's what I have set up: The program goes though a course of specific questions. When the user gives input, that input is put through a function to see if it contains the keyword inv (inventory). If so, the program will display the inventory dictionary. If not, the function will return the original input value for the program to continue.
Here is my current "info" function
def info(s):
inputinventory = s
if inputinventory == 'inv':
print ('\n###INVENTORY###')
#here it would print my dictionary - don't worry about this
#asks user to input again to continue question if 'inv' has been typed
info(input())
else:
#script will return the original input value if 'inv' is not typed
return inputinventory
Implementation of this function:
print ('How old are you? ')
if info(input()) == '12': #just an example
print ('some example text')
elif info(input()) == '13': #the troublesome line
print ('more example text')
The problem I am having is that the elif statement doesn't work as it should since it requires input. This is the way I researched to test the value of a return - I can't find out how else to get it without writing the function over and over again to get what it returns. Is there a way to solve this, or am I making things difficult?
edit: Wait - I bet I can just run the function once and assign it to a variable... Let's try that really quick... but that won't work if the user types "inv" probably