Question
Design a program in Python for a retailer to add up their daily sales. The retailer has many stores in two different states: Virginia and
Design a program in Python for a retailer to add up their daily sales. The retailer has many stores in two different states: Virginia and North Carolina. The user will need to enter the state and the sales amount. If the sales took place in Virginia, the program will add a 5.3% sales tax to the sales amount. If the sales took place in North Carolina, the program will add a 4.75% sales tax. Keep in mind that sales tax change, so design your program so that the amount can easily change. The program will output the sales amount with tax after each store entry for the user to view. The program should allow the user to enter sales from as many stores as they wish. Please make sure that you let the user know how to end the program. When the user is finished entering daily sales the program will list the following in addition to the store totals with tax: The grand total sales for all the stores with tax, The total sales with tax for the stores in each state.
I was given this answer, but I cannot get it to run properly, can someone help me with this?
Expert Answer
Anonymous answered this
Was this answer helpful?
0
0
2 answers
from functools import reduce
#Initializing values
state = None
sales_Virginia = []
sales_NorthCarolina = []
#Setting the tax percentage
virginia_tax = 5.3
north_carolina_tax = 4.75
user_intimated = False
def getInputs(state,user_intimated):
#Informing user as to how to leave application
if not user_intimated:
print ("This application calculates the daily sales by state. Press N at any time to discontinue/leave the application.")
user_intimated = True
#Execute indefinitely until user chooses to discontinue
while True:
#Check if user wishes to continue
if len(sales_Virginia) > 0 or len(sales_NorthCarolina) > 0:
print ("Do you want to continue? [Y/N]")
x = input()
#If not, print the grand total and total per state
if x == "N" or x == "n":
virginia_total = reduce(lambda x,y: x+y,sales_Virginia) if len(sales_Virginia) > 0 else 0
nc_total = reduce(lambda x,y: x+y,sales_NorthCarolina) if len(sales_NorthCarolina) > 0 else 0
print ("Total sales for Virginia:" + str(virginia_total))
print ("Total sales for North Carolina:" + str(nc_total))
print ("Grand total for all stores:" + str(virginia_total + nc_total))
return
print ("***********************************")
#Getting the state input from user
while state is None:
print ("Choose a state (either 1 or 2): [1] Virginia [2] North Carolina")
try:
inp = input()
#If user presses N leave application
if inp == 'N' or inp == 'n':
return
temp = int(inp)
if temp == 1:
state = "Virginia"
elif temp == 2:
state = "North Carolina"
except:
state = None
if state is None:
print ("Invalid input")
sales_amount = -1.0
#Getting the sales amount input from user
print ("Enter the sales amount: ")
while sales_amount == -1.0:
ex = input()
#If user presses N leave application
if ex == 'N' or ex == 'n':
return
sales_amount = float(ex)
if sales_amount == -1.0:
print ("Invalid input. Only numeric values are allowed.")
multiplier = 1 + (virginia_tax/100 if state == "Virginia" else north_carolina_tax/100)
sales_with_tax = sales_amount * multiplier
#Print the sales amount with tax
print ("Sales amount with tax: "+str(sales_with_tax))
#After printing value, store them in list to calculate total later
if state == "Virginia":
sales_Virginia.append(sales_with_tax)
elif state == "North Carolina":
sales_NorthCarolina.append(sales_with_tax)
sales_amount = -1.0
state = None
#Call the main function
getInputs(state,user_intimated)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started