Question

I am looking for PYTHON code that will display the following: Code a menu-driven application that...

I am looking for PYTHON code that will display the following:

Code a menu-driven application that does the following:

The user can enter data for a product name, product code, and unit price.

An example might be 'Breaburn Apples', 'BAP'. 1.99. After entering the data, it is appended (note I said 'appended') as a single line of text to a text file. Each line of text in the file should represent a single product.

There is an option to display the contents of the text file.

The program runs until the user tells it to stop.

Here's a possible run of your program.

Inventory program
1) Enter a product
2) Display all products
3) Quit
Select a menu option: 1

Enter a product
Name: Braeburn Apples
Code: BAP
Price: 1.99

Inventory program
1) Enter a product
2) Display all products
3) Quit
Select a menu option: 1

Enter a product
Name: Joliet Pears
Code: JPR
Price: 3.09

Inventory program
1) Enter a product
2) Display all products
3) Quit
Select a menu option: 2

Products on file...
Braeburn Apples, BAP, 1.99
Joliet Pears, JPR, 3.09

Inventory program
1) Enter a product
2) Display all products
3) Quit
Select a menu option: 3

The program has ended.


If your text file doesn't exist and you attempt to display it, your code will fail. At this time, don't worry about that. However, if you want to code for that potential problem, feel free. You never know when that might be useful.

Homework Answers

Answer #1

Please find the below python code with comments:

#importing required pacakges
import os.path
from os import path
option=1
#checking option
while option!=3 :
   print('Inventory program\n1) Enter a product\n2) Display all products\n3) Quit\nSelect a menu option:',end='')
   #reading choice
   option=int(input())
   if option==1 :
       #we are opening file in append mode so if there is no file it will be created
       f=open("products.txt", "a+")
       print('Enter a product')
       #reading product name
       Name=input('Name:')
       #reading product code
       Code=input('Code:')
       #reading product price
       Price=input('Price:')
       #appending to file with new line
       f.write(Name+','+Code+','+Price+'\n')
       f.close()
   elif option==2 :
       #checking if the file already exists for reading
       if path.exists("products.txt") :
           f=open("products.txt", "r")
           #reading products
           productslist=f.read()
           #displaying products
           print(productslist)
           f.close()
       else :
           print('No such file exists')
   elif option==3 :
       exit()
   else :
       print('Invalid option')

Know the answer?
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
Similar Questions
Hello, I am having trouble getting my files to work together for this problem. Here is...
Hello, I am having trouble getting my files to work together for this problem. Here is the question and thank you for taking the time to answer it :) (1) Write an application that displays a menu of three items for the Jivin’ Java Coffee Shop as follows: American 1.99 Expresso 2.50 Latte 2.15 Prompt the user to choose an item using the number (1, 2, or 3) that corresponds to the item, or to enter 0 to quit the...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player position 6 – Edit player stats 7 - Exit program POSITIONS C, 1B, 2B, 3B, SS, LF, CF, RF, P Team data file could not be found. You can create a new one if you want. ================================================================ Menu option: 2 Name: Mike Position: SS At bats: 0 Hits: 0 Mike was added....
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array in ascending order(use...
Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a...
Problem 1 (Defining products and Creating a Menu) Write a program called a2_p1.py that asks a shop owner for product information and creates a menu system that allows customers to purchase multiple products of varying quantities. The program should start by asking the shop owner’s name (string) and company name (string). Next it should ask for three (3) products (strings), their prices (int – not ideal, but for now we will keep it this way), and the number of products...
--USING C# ONLY-- You will create your own on-line shopping store in the console application. You...
--USING C# ONLY-- You will create your own on-line shopping store in the console application. You can choose different products to sell in your store (at least 8 products). You will create an product inventory text file. The program will display two options at the beginning of the program, Customer and Manager. Customer: If this is a new customer, the program will allow the customer to register with their information and assign a unique ID number to the new customer....
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
Java Create a new Drive class. * Create a Menu class. * The menu class will...
Java Create a new Drive class. * Create a Menu class. * The menu class will use the previous 4 classes you created in GCD, LCM, FACTORIAL, DIGITS The Menu will display a menu that give you the option of selecting: 1) Greatest Common Denominator 2) Lowest Common Multiple 3) Factorial 4) Number of Digits in an Integer Enter 1,2,3 or 4: When the User enter the choice, then the correct function/method is called for the class and asks the...
Write a phython program to display a menu with the following options: (1) add, (2) subtract,...
Write a phython program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. If the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT