Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70261
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-04-15 01:44 -0700 |
| References | <67147571-4509-4476-bc7b-4712688cf7b1@googlegroups.com> <534cede7$0$11109$c3e8da3@news.astraweb.com> |
| Message-ID | <4e425a36-4d63-436d-9083-ac479331bf92@googlegroups.com> (permalink) |
| Subject | Re: Learner looking for assistance |
| From | Anthony Smith <jackie.walkabout@gmail.com> |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Learner looking for assistance Anthony Smith <jackie.walkabout@gmail.com> - 2014-04-14 00:43 -0700
Re: Learner looking for assistance Ben Finney <ben+python@benfinney.id.au> - 2014-04-14 18:11 +1000
Re: Learner looking for assistance Anthony Smith <jackie.walkabout@gmail.com> - 2014-04-14 01:23 -0700
Re:Learner looking for assistance Dave Angel <davea@davea.name> - 2014-04-14 08:34 -0400
Re: Learner looking for assistance Anthony Smith <jackie.walkabout@gmail.com> - 2014-04-15 00:52 -0700
Re: Learner looking for assistance Chris Angelico <rosuav@gmail.com> - 2014-04-15 18:03 +1000
Re: Learner looking for assistance Steven D'Aprano <steve@pearwood.info> - 2014-04-15 08:29 +0000
Re: Learner looking for assistance Anthony Smith <jackie.walkabout@gmail.com> - 2014-04-15 01:44 -0700
csiph-web