by applying some simple algebra to the right hand side
price_per_book - (price_per_book * percent_discount)
"x = (x * 1)" so "price_per_book == (price_per_book * 1)" so rhs becomes
(price_per_book * 1) - (price_per_book * percent_discount)
and "(a * x) - (a * y)" == "a * (x - y)" so rhs becomes
price_per_book * (1 - percent_discount)
hence:
discounted_price = price_per_book * (1 - percent_discount)
The one just looks out of place compare to using properly defined names,(algebra aside) like this:
def order_total():
price_per_book = float(raw_input("Enter price per book: $"))
percent_discount_amount = float(raw_input("Enter percent discount amount(in format example .40): "))
quantity = float(raw_input("Enter quantity of books: "))
first_book_shipping = float(raw_input("Enter first book's shipping: $"))
extra_book_shipping = float(raw_input("Enter extra book's shipping costs: $"))
percent_discount = price_per_book * percent_discount_amount
amount_of_first_books = 1 # of course it would equal 1
discounted_price = price_per_book - percent_discount
shipping = first_book_shipping + ((quantity - amount_of_first_books) * extra_book_shipping)
total_price = (quantity * discounted_price) + shipping
print 'Total price: $%d' % (total_price)
order_total()
************Or Use with params for iterating through larger amounts of books to be calculated*****************
def order_total(price_per_book,percent_discount_amount,quantity,first_book_shipping,extra_book_shipping):
percent_discount = price_per_book * percent_discount_amount
amount_of_first_book = 1 # of course it would equal 1
discounted_price = price_per_book - percent_discount
shipping = first_book_shipping + ((quantity - amount_of_first_book) * extra_book_shipping)
total_price = (quantity * discounted_price) + shipping
print 'Total price: $%d' % (total_price)
price_per_book = float(raw_input("Enter price per book: $"))
percent_discount_amount = float(raw_input("Enter percent discount amount(in format example .40): "))
quantity = float(raw_input("Enter quantity of books: "))
first_book_shipping = float(raw_input("Enter first book's shipping: $"))
extra_book_shipping = float(raw_input("Enter extra book's shipping costs: $"))
order_total(price_per_book,percent_discount_amount,quantity,first_book_shipping,extra_book_shipping)
The numbers just seem out of place when a var can be used that properly defines it, or another way to arrive at the same solution.