Python: Create a program that keeps track of the items that a wizard can carry
Python: Create a program that keeps track of the items that a wizard can carry
Hello im doing a project but I am stuck currently and would like some help.
so far i have
Module 1:(items.py)
def list(inventory_list):
item_list = ["a wooden staff","a wizard hat","a cloak of invisibility",
"some elven bread","an unknown potion","a scroll of uncursing",
"a scroll of invisibility","a crossbow","a wizard's cloak"]
Module 2:
import items as i
import random
inventory_list = 0
def walk(inventory_list):
random.shuffle(i.list)
pickup = i.list(inventory_list).pop()
print("While walking down a path, you see %s." % pickup)
answer_yes = input("Do you want to grab it? (y/n): ")
##def show():
## i = 1
## for item in i.list(inventory_list):
## print(str(i) + ". " + item)
## i += 1
## print()
##
## def drop():
## number = int(input("Number: "))
## if number < 1 or number > len(inventory_list):
## print("Invalid inventory number.n")
## else:
## item = inventory_list.pop(number-1)
## print(item + " was dropped.n")
def display_menu():
print("The Wizard Inventory program")
print()
print("COMMAND MENU")
print("walk - Walk down the path")
print("show - Show all items")
print("drop - Drop an item")
print("exit - Exit program")
print()
def main():
display_menu()
while True:
command = input ("Command: ")
if command.lower() == "show":
show(i.list)
elif command.lower() == "walk":
walk(i.list(inventory_list))
elif command.lower() == "drop":
drop(i.list)
elif command.lower() == "exit":
break
else:
print("Not a valid command. Try again.n")
print("Bye!")
if __name__== "__main__":
main()
Please assist me with me errors I am still a noob. I think I did my code correctly but I obviously didn't because it won't run :(
my main problem at the moments is when running it, the pyhton shell says Traceback (most recent call last):
File "/Users/jamesonmarzak/Documents/project7_JHM.py", line 13, in
pickup = i.list(inventory_list).pop()
AttributeError: 'NoneType' object has no attribute 'pop'
Ive been messing with it but right now it says break is outside of the loop. Ive been trying to fix it but i keep ending up with the same syntax error
– Jameson Marzak
Jul 2 at 18:46
I was able to get rid of that syntax error and it will run but it comes up with the error "Traceback (most recent call last): File "/Users/jamesonmarzak/Documents/project7_JHM.py", line 13, in <module> pickup = i.list(inventory_list).pop() AttributeError: 'NoneType' object has no attribute 'pop'"
– Jameson Marzak
Jul 2 at 18:50
Generally means the list was A) not initialized or B) cleared before line 13. I can take a look a bit later; ping me on chat.stackoverflow.com/rooms/166968/the-ai-hub
– frank
Jul 2 at 19:10
Apparently you need certain reputation to chat, though. So just ping me here
– frank
Jul 2 at 19:29
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Hi, welcome to SO! What is the error your computer spits out when you run the code? Are you using command line? IDE?
– frank
Jul 2 at 18:45