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 Command: walk Command: walk Command: show Command: drop Command: exit Thank you for using my app. |
Specifications
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
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
code snaps
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.
Python Subject Output in Thonny ot IDLE Description Create a program that keeps track of the...
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 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 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 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 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 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 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 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...
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 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...