hello,
i've an absolute beginner and i'm trying to create a zork like text based game to learn. I have 2 questions, the first is that when I add 2 items to the list "inventory" it displays them like this:
flask, knife
flask, knife
so it displays them twice and i'm not sure why, also, i'd like it to just display them each on a different line such as
flask
knife
secondly, i'm sure what I have done so far is a really bad an inefficient way of doing it, are there any tips or ideas I could use to write it better and re-use certain code for the commands etc before I go further? thanks a lot
import os, random, time
global name
name = "unknown"
inventory = []
def displayinventory():
print("\nInventory:")
for i in inventory:
print(inventory)
def introduction():
global name
print("banner")
print("do intro text")
name = str(input("Your name:"))
def easternfields():
here = 1
knifetaken = 0
print("\nEastern Fields")
print("\nDescription")
while here == 1:
command = str(input("> "))
command.lower()
lowcommand = command.lower()
if lowcommand == "inv":
displayinventory()
elif lowcommand == "look":
print("\nYou look around the eastern fields")
elif lowcommand == "take knife" and knifetaken != 1:
print("\nknife taken.")
knifetaken = 1
inventory.append('knife')
lowcommand = ""
elif lowcommand == "take knife" and knifetaken == 1:
print("knife already taken")
elif lowcommand == "drop":
whichitem = str(input("item: "))
if whichitem in inventory:
inventory.remove(whichitem)
else:
print("\nCommand not recognised")
def southernfields():
here = 1
flasktaken = 0
print("\nSouthern Fields")
print("\nDescription")
while here == 1:
command = str(input("> "))
command.lower()
lowcommand = command.lower()
if lowcommand == "inv":
displayinventory()
elif lowcommand == "look":
print("\nYou look around the southern fields")
elif lowcommand == "take flask" and flasktaken != 1:
print("\nflask taken.")
flasktaken = 1
inventory.append('flask')
lowcommand = ""
elif lowcommand == "take flask" and flasktaken == 1:
print("flask already taken")
elif lowcommand == "drop":
whichitem = str(input("item: "))
if whichitem in inventory:
inventory.remove(whichitem)
elif lowcommand == "go east":
here = 0
easternfields()
else:
print("\nCommand not recognised")
southernfields()