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
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....
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...
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...
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...
--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....
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...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write a menu-driven program for  Food Court. (You need to use functions!) Display the food menu to a user . 5 options Use numbers for the options and for example "6" to exit. Ask the user what he/she wants and how many of it. (Check the user inputs) AND use strip() function to strip your inputs(if needed) Keep asking the user until he/she chooses the exit...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • A digital signal has four levels. How many bits are needed per level? Draw the digital...
    asked 5 minutes ago
  • Case X Case Y Case Z Cash $ 2,550 $ 260 $ 1,300 Short-term investments 0...
    asked 16 minutes ago
  • At elevated temperatures, sodium chlorate decomposes to produce sodium chloride and oxygen gas. A 0.8655-g sample...
    asked 33 minutes ago
  • Part 1 – Sociological Perspectives A. Early social thinkers were concerned about order and stability in...
    asked 42 minutes ago
  • To make lemonade, Karman uses one part lemon juice to 5 parts water. Her family drinks...
    asked 42 minutes ago
  • A Ferris wheel 22.0 m in diameter rotates once every 12.5 s. What is the ratio...
    asked 46 minutes ago
  • A college student in an Introduction to Psychology class is learning the concepts of attention and...
    asked 55 minutes ago
  • The first rule of good behavior is always be yourself. Therefore, professional actors, who adopt the...
    asked 1 hour ago
  • simple python probelm finish quick will rate Problеm: Givеn thе providеd Budgеt and DrawRеquеsts data, fill...
    asked 1 hour ago
  • A cylindrical metal can, 0.1 m high and 0.05 m in diameter, contains liquid helium at...
    asked 1 hour ago
  • I am looking for PYTHON code that will display the following: Code a menu-driven application that...
    asked 2 hours ago
  • Astudentlearnsthationiccompoundshavesignificantcovalentcharacterwhenacationhasapolarizingeffect on a large anion. As a result, the student hypothesizes that salts composed of small...
    asked 2 hours ago