Learner looking for assistance

Anthony Smith jackie.walkabout at gmail.com
Tue Apr 15 04:44:02 EDT 2014


On Tuesday, 15 April 2014 18:29:27 UTC+10, Steven D'Aprano  wrote:
> On Mon, 14 Apr 2014 00:43:41 -0700, Anthony Smith wrote:
> 
> 
> 
> 
> 
> > the calc_total does not return a estimated_total_weight
> 
> 
> 
> That's because you don't tell it to. Your calc_total method multiplies by 
> 
> estimated_weight_hd which is not the same as estimated_total_weight.
> 
> 
> 
> > 
> 
> > if add the estimated_total_weight the rest of the code works
> 
> > I am at a lose as to why ?????
> 
> 
> 
> What does "works" mean in this context? What is the code supposed to do, 
> 
> and what does it do instead?
> 
> 
> 
> Because you have only given us a tiny snippet of code, we have no way of 
> 
> running it. Please read this page here:
> 
> 
> 
> http://www.sscce.org/
> 
> 
> 
> 
> 
> and try to prepare a short, working (in the sense that it runs and 
> 
> demonstrates the problem) example.
> 
> 
> 
>  
> 
> > def calc_total(self):
> 
> >     	amount = 0
> 
> >     	if self.estimated_weight_hd > 0:
> 
> >             amount = self.number * self.estimated_weight_hd
> 
> > 	return amount
> 
> 
> 
> This only adds the weight to amount if it is positive. If it is negative, 
> 
> nothing happens. Is that deliberate? Also, I see you have mixed spaces 
> 
> and tabs. Please use one, or the other, but never use both. Mixing spaces 
> 
> and tabs will give you no end of headaches.
> 
> 
> 
> 
> 
> > 	def save(self):
> 
> > 		self.estimated_total_weight = self.calc_total()
> 
> >     		super(SaleNote, self).save()
> 
> 
> 
> This appears to be indented *inside* the calc_total method, but after the 
> 
> return statement, it is dead code and will never be executed. Or perhaps 
> 
> not -- because you have mixed spaces and tabs, it is very difficult to 
> 
> tell.
> 
> 
> 
> 
> 
> >     def calc_total_price(self):
> 
> >     	amount_price = 0
> 
> > 	if self.sale_head > 0:
> 
> > 	    amount_price = self.number * self.sale_head
> 
> >             return amount_price
> 
> >         else:
> 
> >             if self.estimated_total_weight > 0:
> 
> >                 amount_price = self.estimated_total_weight *
> 
> >                 self.sale_kg
> 
> > 	return amount_price
> 
> 
> 
> Without knowing what your code is supposed to do, we cannot tell how it 
> 
> is broken. What is self.sale_head? Under what circumstances is is 
> 
> negative?
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Sale head is a positive 
if sale head is used the first function is not required 

but if it is not used the first function is used 

then the last function is used to calculate the total price 



More information about the Python-list mailing list