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
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.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...
Need help debugging. Create an application that keeps track of the items that a wizard can carry. console application which has no errors: import java.util.Scanner; public class Console { private static Scanner sc = new Scanner(System.in); public static String getString(String prompt) { System.out.print(prompt); String s = sc.nextLine(); return s; } public static int getInt(String prompt) { int i = 0; boolean isValid = false; while (!isValid) { System.out.print(prompt);...
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...
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...
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...
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...
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...
PLEASE FOLLOW ALL DIRECTIONS AND CONFIRM BEFORE
SUBMITTING ANSWER. EXAMPLES OF HOW THE PROGRAM SHOULD LOOK AND WORK
ARE DOWN BELOW. I REALLY NEED THIS ANSWERED AS SOON AS POSSIBLE.
PLEASE AND THANK YOU!!!
1. Write a Java program that solves a maze Maze is an exciting
puzzle game whose goal is to find the path from a starting position
(S) to an end position (E ).
2. Important functions for the program
Reading a maze file
After reading 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...
Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu: Enter Circle Enter Rectangle Remove Shape Draw Shapes Exit Circles – User inputs position, radius, and color. The position is the CENTER of the circle Rectangles – User inputs position, height, width, color. The position is the lower left-hand corner Colors – Allow red, yellow, blue, and green only Remove – Show the number of items in the list and let the user enter...