# Help with some python homework...

David Hutto dwightdhutto at gmail.com
Sun Feb 2 20:08:40 CET 2014

```Or a better iterating example for a database of shipping, or ordering books would be:

import random as r
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 "Book XYZ-%d-ABC \nPrice per book: \$%d\nPercent discount amount: %f\nQuantity of books: %f\nFirst book's shipping: \$%f\nextra_book_shipping: \$%f\nTotal price: \$%f\n" % (books,price_per_book,percent_discount_amount,quantity,first_book_shipping,extra_book_shipping,total_price)

if __name__ == '__main__':
for books in range(0,10):
price_per_book = float(r.randint(1,100))
percent_discount_amount = float(".%d" % r.randint(0,100))
quantity = float(r.randint(0,100))
first_book_shipping = float(r.randint(0,100))
extra_book_shipping = float(r.randint(0,100))

order_total(price_per_book,percent_discount_amount,quantity,first_book_shipping,extra_book_shipping)

```