python program algorithm steps for retail bill
Answers
# This loop will go on until the budget is integer or float
while True:
try:
bg = float(input("Enter your budget : "))
# if budget is integer or float it will be stored
# temporarily in variable 's'
s = bg
except ValueError:
print("PRINT NUMBER AS A AMOUNT")
continue
else:
break
# dictionary to store product("name"), quantity("quant"),
# price("price") with empty list as their values
a ={"name":[], "quant":[], "price":[]}
# converting dictionary to list for further updation
b = list(a.values())
# variable na value of "name" from dictionary 'a'
na = b[0]
# variable qu value of "quant" from dictionary 'a'
qu = b[1]
# variable pr value of "price" from dictionary 'a'
pr = b[2]
# This loop terminates when user select 2.EXIT option when asked
# in try it will ask user for an option as an integer (1 or 2)
# if correct then proceed else continue asking options
while True:
try:
ch = int(input("1.ADD\n2.EXIT\nEnter your choice : "))
except ValueError:
print("\nERROR: Choose only digits from the given option")
continue
else:
# check the budget is greater than zero and option selected
# by user is 1 i.e. to add an item
if ch == 1 and s>0:
# input products name
pn = input("Enter product name : ")
# input quantity of product
q = input("Enter quantity : ")
# input price of the product
p = float(input("Enter price of the product : "))
if p>s:
# checks if price is less than budget
print("\nCAN, T BUT THE PRODUCT")
continue
else:
# checks if product name already in list
if pn in na:
# find the index of that product
ind = na.index(pn)
# remove quantity from "quant" index of the product
qu.remove(qu[ind])
# remove price from "price" index of the product
pr.remove(pr[ind])
# insert new value given by user earlier
qu.insert(ind, q)
# insert new value given by user earlier
pr.insert(ind, p)
# subtracting the price from the budget and assign
# it to 's' sum(pr) is because pr = [100, 200] if
# budget is 500 then s = bg-sum(pr) = 200
# after updating for same product at index 0 let
# pr = [200, 200] so s = 100
s = bg-sum(pr)
print("\namount left", s)
else:
# append value of in "name", "quantity", "price"
na.append(pn)
# as na = b[0] it will append all the value in the
# list eg: "name":["rice"]
qu.append(q)
# same for quantity and price
pr.append(p)
# after appending new value the sum in price
# as to be calculated
s = bg-sum(pr)
print("\namount left", s)
# if budget goes zero print "NO BUDGET"
elif s<= 0:
print("\nNO BUDGET")
else:
break
# will print amount left in variable 's'
print("\nAmount left : Rs.", s)
# if the amount left equals to any amount in price list
if s in pr:
# then printing the name of the product which can buy
print("\nAmount left can buy you a", na[pr.index(s)])
print("\n\n\nGROCERY LIST")
# print final grocery list
for i in range(len(na)):
print(na[i], qu[i], pr[i])
Answer:
Python program algorithm steps for retail bill
Explanation:
This is a simple greedy algorithm. We just need to sort all the prices in descending order and group them into 4 per order. The last order might contain less than 4 items.
Here is the Algorithm:
Step 1: Start
Step 2: products.txt file from given folder.
Step 3: txt file is displayed in the screen with products available.
Step 4: Inputs customers name.
Step 5: Inputs products name.
Step 6: If product name is correct then go to next step or else remain in same step until valid name is provided.
Step 7: Input quantity of the product.
Step 8: If the input number of quantity is available then go to next step or else display Sorry!! a_name !, product is out of stock. We will add stock of product later. Lets hope, you will get this product after next shopping
Step 9: Ask customer do you want buy more products?(Y/N) If they select Y, go back to step 6, If they select no, then it won’t go to any steps.
Step10: Price of the product with total amount is displayed.
Step 11: The percentage to be discounted is asked.
Step 12: Total price after the discount is calculated and display updated amount.
Step 13: Invoice is printed with customer name, date and time purchase. Products details, Grand total and at last Thank You customer for your shopping. See you again!
Step 14: If more customers are there to purchase item ‘Y’ should be clicked and go to step or else end.
Step 15: End.
Program:
file is set to open("products.txt","r")
lines is set to file.readlines()
L is set to []
for line in lines:
L.append(line.replace("\n","").split(","))
file.close()
for i in range(len(L)):
output(L[i][0],"\t PRICE: ",L[i][1],"\t QUANTITY: ",L[i][2]) # the availability, price and quantity of the product will output
return L
For more related question : https://brainly.in/question/11818321
#SPJ1
#SPJ1