Question

Python Subject Output in Thonny ot IDLE Description Create a program that keeps track of the...

Python Subject

Output in Thonny ot IDLE

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

Sample Output (Your output should be similar to the text in the following box)

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 cannot 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

Thank you for using my app.

Specifications

  • In your program, use this text file: wizard_all_items.txtPreview the document for a list of all the items and create a new text file: wizard_inventory.txt to store the items that the wizard is currently carrying.
  • Your program should define the following functions:
    • main( )
    • read_items( ): Reads all items from wizard_all_items.txt
    • read_inventory( ): Reads all items from wizard_inventory.txt
    • write_inventory( ): Updates wizard_inventory.txt
    • display_title( ): Displays the application title
    • display_menu( ): Display the command menu
    • walk( ): Picks one item randomly
    • show( ): Shows all items in the inventory
    • drop( ): Drops one item from the inventory
  • When the user selects the walk command, the program should read all items from the file, use random.choice( ) to randomly pick one item from the list, and give the user the option to whether grab it or not.
  • The wizard can only carry four items at a time.
  • Make sure to update this file every time the user grabs or drops an item.
  • For the drop command, display an error message if the user enters an invalid number for the item.

Wizard_all_items.txt

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

import random
wizard_all_items=[]
wizard_inventory_items=[]
def display_menu():
print("\nCOMMAND MENU")
print("walk - Walk down the path")
print("show - Show all items")
print("drop - Drop an item")
print("exit - Exit program")

def read_items():
f = open('wizard_all_items.txt')
line = f.readline()
while line:
wizard_all_items.append(line.rstrip())
line = f.readline()
f.close()


def read_inventory():
try:
f = open('wizard_inventory.txt')
line = f.readline()
while line:
wizard_inventory_items.append(line.rstrip())
line = f.readline()
f.close()
except IOError:
return

def write_inventory():
f= open("wizard_inventory.txt","w+")
for item in wizard_inventory_items:
f.write(item+"\n")

def display_title():
print("The Wizard Inventory program")

def walk():
print("While walking down a path, ",end="")
randomItem=random.choice(wizard_all_items)
print(randomItem)
choice=input("Do you want to grab it? (y/n): ")
if(choice=="Y" or choice=="y"):
if(len(wizard_inventory_items)<4):
wizard_inventory_items.append(randomItem)
wizard_all_items.remove(randomItem)
write_inventory()
else:
print("You cannot carry any more items. Drop something first.")


def show():
if len(wizard_inventory_items)==0:
print("Empty")
i=1
for item in wizard_inventory_items:
print(i," ",item)
i+=1

def drop():
choice=int(input("Number: "))
choice-=1
if(choice>=0 and choice<len(wizard_inventory_items)):
item=wizard_inventory_items.pop(choice)
print("You dropped ",item)
wizard_all_items.append(item)
write_inventory()
else:
print("Invalid choice.")

def main():
wizard_all_items=read_items()
wizard_inventory_items=read_inventory()
while True:
print()
display_menu()
command=input("Command:" )
command=command.lower()
if command=="walk":
walk()
elif command=="show":
show()
elif command=="drop":
drop()
elif command=="exit":
break
print("Thank you for using my app.")

if __name__ == '__main__':
main()

output

C. Command Prompt B:\Chegg\Python>py wizard.py COMMAND MENU walk show - Show all items drop - Drop an item exit - Exit prograC. Command Prompt COMMAND MENU walk show - drop - Drop an item exit - Exit program Command: walk Walk down the path - Show al4. Command Prompt 4 some elven bread COMMAND MENU walk show - Show all items Walk down the path drop - Drop an item exit - Ex

code snaps

O wizard.py – B:\Chegg\Python Atom File Edit View Selection Find Packages Help wizard.py personClassWithCallMethod.py importO wizard.py – B:\Chegg\Python – Atom File Edit View Selection Find Packages Help wizard.py personClassWithCallMethod.py f.cloO wizard.py – B:Chegg\Python – Atom File Edit View Selection Find Packages Help wizard.py personClassWithCallMethod.py det shO wizard.py – B:Chegg\Python – Atom File Edit View Selection Find Packages Help wizard.py personClassWithCallMethod.py item=w

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Python Subject Output in Thonny ot IDLE Description Create a program that keeps track of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help building code in python for this: Create a program that: Creates a sales...

    I need help building code in python for this: Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file Prompt the user to enter the Item Name Item Quantity Item Price Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made Save the item name, quantity, item price, and extended price to a file...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Java program Program: Grade Stats In this program you will create a utility to calculate and...

    Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...

  • Subject: Advance application development Visual studio exercise The project is to create a simple Notepad style Tex...

    Subject: Advance application development Visual studio exercise The project is to create a simple Notepad style Text Editor. This will demonstrate the C# language basics. user interface controls and how to handle user events. Controls can be found in the Toolbox pane in its default location on the left side of the IDE, with the Control Properties pane on the right side of the IDE. Include the items on the following list in the program Create a C# Windows Forms...

  • Need a program in python. Asterix and Obelix want to store and process information about movies...

    Need a program in python. Asterix and Obelix want to store and process information about movies they are interested in. So, you have been commissioned to write a program in Python to automate this. Since they are not very computer literate, your program must be easy for them to use. They want to store the information in a comma separated text file. Using this they would need to generate a report – see all items AND show a bar chart...

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • In C++ General Description: For this project, you will write a program that keeps track of...

    In C++ General Description: For this project, you will write a program that keeps track of inventory for a camera store. The data is located in the file Inventory.txt on the S:\ drive. While the program is running, the information should be stored in a linked list. 1. The information for each item will be stored in a struct a. The definition will be in a separate file called item.h 2. The total inventory will be stored in a linked...

  • Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A...

    Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...

  • Shopping Cart You are to write a program that reads the name of the item, the quantity of each it...

    C++ language Shopping Cart You are to write a program that reads the name of the item, the quantity of each item, and the cost per item from a file. The program will then print out the item and how much is owed for each item. After everything is read in, it will print out the total cost of the cart. Your program should have the following functions main - This function asks the user to enter a filename and...

  • Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a...

    Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a square. Sample Output (Your output should be similar to the text in the following box) Rectangle Calculator Rectangle or square? (r/s): r Height: 5 Width: 10 Perimeter: 30 Area: 50 Continue? (y/n): y Rectangle or square? (r/s): s Length: 5 Perimeter: 20 Area: 25 Continue? (y/n): n Thank you for using my app Specifications Use a Rectangle class that provides attributes to store the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT