Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65277

Re: Help with some python homework...

Newsgroups comp.lang.python
Date 2014-02-02 10:09 -0800
References (1 earlier) <mailman.6264.1391232938.18130.python-list@python.org> <d8c2b5bd-d56d-4327-b219-85f0b304b187@googlegroups.com> <mailman.6308.1391359140.18130.python-list@python.org> <be2d121a-fa68-41b3-b5b6-790d52f009a5@googlegroups.com> <lcm035$70b$1@dont-email.me>
Message-ID <dcce80cc-e633-4a13-9d10-1efef79c0cef@googlegroups.com> (permalink)
Subject Re: Help with some python homework...
From David Hutto <dwightdhutto@gmail.com>

Show all headers | View raw


On Sunday, February 2, 2014 12:43:01 PM UTC-5, Denis McMahon wrote:
> On Sun, 02 Feb 2014 08:57:03 -0800, David Hutto wrote:
> 
> 
> 
> > Revised:
> 
> 
> 
> > discounted_price = price_per_book - (price_per_book * percent_discount)
> 
> 
> 
> 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)
> 
> 
> 
> -- 
> 
> Denis McMahon

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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help with some python homework... scottwd80@gmail.com - 2014-01-30 21:12 -0800
  Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-01-31 16:30 +1100
    Re: Help with some python homework... sjud9227 <scottwd80@gmail.com> - 2014-01-30 22:24 -0800
      Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-01-31 17:38 +1100
        Re: Help with some python homework... sjud9227 <scottwd80@gmail.com> - 2014-01-30 22:48 -0800
      Re: Help with some python homework... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 21:17 +1300
        Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-01-31 19:30 +1100
          Re: Help with some python homework... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 23:46 +1300
        Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-02-01 11:57 +1100
        Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-02-01 12:34 +1100
        Re: Help with some python homework... David <bouncingcats@gmail.com> - 2014-02-01 14:17 +1100
        Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 18:14 -0700
          Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-01 19:32 +0000
            Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 17:12 -0800
              Re: Help with some python homework... Larry Hudson <orgnut@yahoo.com> - 2014-02-02 23:48 -0800
        Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:46 -0700
        Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:42 -0700
        Re: Help with some python homework... David <bouncingcats@gmail.com> - 2014-02-01 17:13 +1100
        Re: Help with some python homework... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-01 10:44 -0500
  Re: Help with some python homework... Neil Cerutti <neilc@norwich.edu> - 2014-01-31 13:51 +0000
  Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-01 03:02 +0000
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:35 -0700
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 22:18 -0700
    Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-01 19:45 +0000
    Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 08:11 -0800
      Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 08:36 -0800
      Re: Help with some python homework... MRAB <python@mrabarnett.plus.com> - 2014-02-02 16:38 +0000
        Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 08:57 -0800
          Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-02 17:43 +0000
            Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 10:09 -0800
            Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 11:08 -0800
              Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 11:21 -0800
    Re: Help with some python homework... "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-02 17:15 +0000
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 22:04 -0700
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:07 -0700
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 22:19 -0700
  Re: Help with some python homework... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-01 10:50 -0500
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-02-01 23:06 -0700

csiph-web