Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 7-2: Wizard Inventory (python code) Create a program that keeps track of the items that a wizard can carry. Console The Wizard Inventory program

Project 7-2: Wizard Inventory (python code)

Create a program that keeps track of the items that a wizard can carry.

Console

The Wizard Inventory program 
COMMAND MENU walk - Walk down the path show - Show all items drop - Drop an item exit - Exit program 
Command: walk While walking down a path, you see a scroll of uncursing. Do you want to grab it? (y/n): y You picked up a scroll of uncursing. 
Command: walk While walking down a path, you see an unknown potion. Do you want to grab it? (y/n): y You can't carry any more items. Drop something first. 
Command: show 1. a wooden staff 2. a scroll of invisibility 3. a crossbow 4. a scroll of uncursing 
Command: drop Number: 3 You dropped a crossbow. 
Command: exit Bye! 

Specifications

Your instructor should provide a text file named wizard_all_items.txt that contains a list of all the items that a wizard can carry.

This is the text file provided:

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

When the user selects the walk command, the program should read the items from the file, randomly pick one, and give the user the option to grab it.

Your program should create another file that stores the items that the wizard is carrying. Make sure to update this file every time the user grabs or drops an item.

The wizard can only carry four items at a time.

For the drop command, display an error message if the user enters an invalid number

for the item.

This is what I have so far:

First Module: "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"]

Second module: "project7-2.py

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. ")

## else:

## item = inventory_list.pop(number-1)

## print(item + " was dropped. ")

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 items")

print("exit - Exit ptogram")

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. ")

print("Bye!")

if __name__== "__main__":

main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions

Question

What is operatiing system?

Answered: 1 week ago

Question

Develop clear policy statements.

Answered: 1 week ago

Question

Draft a business plan.

Answered: 1 week ago

Question

Describe the guidelines for appropriate use of the direct plan.

Answered: 1 week ago