0

I am a fairly new programmer, and I wanted to create a text based RPG, in which the user could type in a command, which allows them to open their bag (which I am creating using a list) I have the list variable, and I have most of the game running through if, elif, and else statements. I was not sure how to allow the user to type a command to be able to see what they have in their bag/inventory

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Saju
  • 31
  • 3
  • 1
    Would it be possible for you to post some code? Without it, all I can suggest is using `print()` to print the list and `input()` to get commands from the user. – maldata Aug 17 '21 at 02:45
  • I am not sure what really to post, but I basically want the user to be able to type out "bag" while answering the questions of the game, and that allows them to see the inventory. I can't explain it too well, but the user should be able to command to print(bag) – Saju Aug 17 '21 at 02:53
  • Is there any way that I can add the code, because it is over the limit and I am not really sure how StackOverflow works too well – Saju Aug 17 '21 at 02:55

1 Answers1

1

Here's a very simple example:

def main():
    bag = ['a', 'list', 'of', 'things']
    cmd = input('Enter a command: ')

    if cmd == "bag":
        print(bag)
    else:
        print("I don't know what to do with {0}.".format(cmd))
    
    
if __name__ == '__main__':
    main()
maldata
  • 385
  • 1
  • 14
  • Thank you so much, I just tested it out and it worked. I'm just curious, if you don't mind answering. What is the if statement at the bottom doing? – Saju Aug 17 '21 at 03:14
  • 1
    There's a good answer here: https://stackoverflow.com/questions/419163/what-does-if-name-main-do – maldata Aug 17 '21 at 03:15