# tpm.py
# A program that accepts the total amount of purchase, calculates the
# appropriate discount, and displays the discount and the purchase after
# discount.

from math import *

def main():
cost = get_cost()
discount = get_discount()
% = calc_percent(discount)
final cost = get_final_cost
cost_percent = cost_discount(cost, discount)
show_result(cost_discount_final_cost)

def get_cost():
return float(raw_input("Enter the cost before discount: "))

def get_discount():
return float(raw_input("Enter your discount is: "))

def calc_percent(discount)
% = 0.10 on the entire purchase if it exceeds \$1,000.00
% = 0.05 on the entire purchase if it exceeds \$500.00, but not \$1,000.00
print "No discount on puchases of \$500.00 or less

:o

## All 4 Replies

Since your discount is calculated from the total purchase, you do not need to ask for it.
Discount calculations are done using conditional if statements.

Do not use % as a variable name!

All calculations are simple, no need for "from math import *"

can you show me please i tried using using the if statements

You are almost there, please try to understand the logic here ...

``````def calc_discount(cost):
if cost > 1000.00:
discount = cost * 0.1    # 10%
return discount
elif cost > 500.00:
discount = cost * 0.05   # 5%
return discount
else:
# no discount
return 0.0``````

Once you know the cost of the purchase then discount = calc_discount(cost) and your final cost will be cost - discount. Not really rocket science, but very simple algebra!

thank you...it helped alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.