Exercise: Toupee pricing Write a program to estimate the price of toupees. There
ID: 3788834 • Letter: E
Question
Exercise: Toupee pricing
Write a program to estimate the price of toupees. There are three models: rug, mop, and silky. The price per unit depends on the order amount:
Your worksheet starts like this:
The user enters a model, a quantity, and clicks Run.
Your program validates both inputs. Model should be R, M, or S. Your program should work for upper- and lowercase, and if there are spaces before or after the character (e.g., “ r “ is OK). Show error messages as needed.
Quantity must be a number that’s one or greater. Show error messages as needed.
The total is price per unit times number ordered.
The usual coding standards apply.
Model Quantity Price per unit Rug 1 – 9 $89.95 Rug 10 – 29 $79.95 Rug 30 or more $64.95 Mop 1 – 9 $129.95 Mop 10 – 29 $109.95 Mop 30 or more $89.95 Silky 1 – 9 $229.95 Silky 10 – 29 $189.95 Silky 30 or more $149.95 1 Toupee Price Estimate 3 Model (R, M, S) 5 Quantity Run 9 Price:Explanation / Answer
#Python code for given problem statement
#Following code validate all inputs and also takes lowercase and uppercase letter
print "Enter the order type"
c=raw_input().strip() #strip() method removes all spaces in front and back of character
#print c
print "Enter the quantity"
q=input()
price=0
if(c=='r' or c=='R'):
if(q<10 and q>=1):
price=q*89.95
elif(q<30 and q>=10):
price=q*79.95
else:
price=q*64.95
elif(c=='m' or c=='M'):
if(q<10 and q>=1):
price=q*129.95
elif(q<30 and q>=10):
price=q*109.95
else:
price=q*89.95
elif(c=='s' or c=='S'):
if(q<10 and q>=1):
price=q*229.95
elif(q<30 and q>=10):
price=q*189.95
else:
price=q*149.95
else:
print "Wrong choice"
exit()
print price
#Output :
G580:~/codes/schegg$python toupee.py
Enter the order type
r
Enter the quantity
3
269.85
G580:~/codes/schegg$ python toupee.py
Enter the order type
d
Enter the quantity
43
Wrong choice
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.