Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When running the following Python code I am getting an error when the quantity of either the A widget or B widget is negative, instead

When running the following Python code I am getting an error when the quantity of either the A widget or B widget is negative, instead of it printing the error statement.

def user_input(): name=input("Enter name: ") wA=int(input("Enter quantity of widget A ordered: ")) while(wA<=0): wA=int(input("Invalid...Please enter positive quantity",name)) wB=int(input("Enter quantity of widget B ordered: ")) while(wB<=0): wB=int(input("Invalid...Please enter positive quantity",name)) ch=input("Is this order for out of state(Y/N)? ") return name,wA,wB,ch def disc(wA,wB,code) : discount_A=discount_B=0 if(wA>10): discount_A=(wA*int(code[0])) if(wB>5): discount_B=(wB*int(code[1])) return discount_A, discount_B

def sales_tax(ch,price): t=0 if(ch=='N'): t=price*7.5/100 else: t=price**5/100 return t

def shipping(ch,w): ship=0 if(ch=='Y'): ship=2*w else: ship=1.15*w return ship

def total_cost(): widgetA=0 widgetB=0 code='23' ship=0 tax=0 handling_cost=12.50 name,A,B,c=user_input() discountA,discountB=disc(A,B,code) widgetA=17*A-discountA widgetB=23*B-discountB tax=sales_tax(c,widgetA+widgetB) ship=shipping(c,A+B) print("..........%s.........."%name) print("Quantity of widget A ordered: ",A) print("Quantity of widget B ordered: ",B) print("Discount on quantity of widget A: $",discountA) print("Discount on quantity of widget B: $",discountB) print("Total cost of widget A after discount: $",widgetA) print("Total cost of widget B after discount: $",widgetB) print("Sales tax on total cost: $",tax) print("Shipping on total cost: $ %.2f"%ship) print("Handling cost: $",handling_cost) total_price=widgetA+widgetB+tax+ship+handling_cost return total_price print("Total cost: $ %.2f"%total_cost())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions