954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Is This The Correct Way To Do This..Can You Help Me.

# 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

butterflyTee
Light Poster
43 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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 *"

bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
 

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

butterflyTee
Light Poster
43 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

You are almost there, please try to understand the logic here ...
[php]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
[/php]
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!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

thank you...it helped alot

butterflyTee
Light Poster
43 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You