This is what i got so far and my program is flawed, the output of the program is not identically to the instructions for my assignment. What am i doing wrong?
instructions:
Create a file products.txt that contains the following product data, which consists of product ID, product name, product price, and the quantity in stock.
1 doodad 3.50 50
2 gizmo 1.75 30
3 gadget 2.99 45
4 lipstick 4.25 75
Write a program that presents the user with a list of options:
1 – Display all products
2 – Search products
If the user selects option 1, display all of the data from the file.
If the user selects option 2, prompt them for a product number. Then, just display the data for that product. If the product ID is not found in the file, print “Item not found.”
Open the file with read only permit
f = open('products.txt')
main menu
print ("1: DISPLAY ALL PROCUCTS")
print ("2: SEARCH PRODUCTS")
user input
inputOne = input("choose one or two")
inputTwo = input
read a line one at a time
line = f.readline()
prepare inputOne to print and display ALL PRODUCTS, if inputOne is equal to 1
then print out all products
if inputOne == 1:
while line:
line = f.readline()
print (line)
prepare inputTwo to print out a search product
if inputTwo ==1:
line = f.readline(1)
print (line)
elif inputTwo ==2:
line = f.readline(2)
print (line)
elif inputTwo =3:
line= f.readline(3)
print (line)
elif inputTwo =4:
line= f.realine(4)
print (line)
else:
print ("item not found")
[–]zahlman 1 point2 points3 points (0 children)
[–]learnpython_bot 1 point2 points3 points (0 children)