If statement issue driving me nuts

A

Anthony Smith

Hi

I have a small project and I have been unable to get the following statement to work. Any help would great.
User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight,
the code below should return a estimated_weight_total which can be used for the total sale price.
All works when I add the estimated_weight_total manually. I am lost as why.

def calc_estimated_weight_total(self):
if self.sale_head <= 0:
amount = (self.number * self.estimated_weight_hd)
return amount

def save(self):
self.estimated_total_weight = self.calc_estimated_weight_total()
super(SaleNote, self).save()
 
D

Dave Angel

Anthony Smith said:
Hi

I have a small project and I have been unable to get the following statement to work. Any help would great.
User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight,
the code below should return a estimated_weight_total which can be used for the total sale price.
All works when I add the estimated_weight_total manually. I am lost as why.

def calc_estimated_weight_total(self):
if self.sale_head <= 0:
amount = (self.number * self.estimated_weight_hd)
return amount

def save(self):
self.estimated_total_weight = self.calc_estimated_weight_total()
super(SaleNote, self).save()

Please insert the missing words, and fix the punctuation, and
maybe we'll be able to decipher your question. Your subject line
implies you think there's a problem with the if statement;
perhaps you could describe what problem that is. You might even
try to describe what the sale_head attribute is supposed to
be.

Then post a useful fragment of code, and state what resulted, and
what you expected that was different. If you got an exception,
paste the whole thing

Ideally post a runnable hunk of code.

One problem with your first method is that you don't return an
amount in the (missing) else clause. So if the condition is
false, the caller will see None instead of a number. If it
happens to be called from the save method, you'll get an
exception.
 
G

Gary Herron

Hi

I have a small project and I have been unable to get the following statement to work. Any help would great.
User inputs can either self_sale_head which is a $ value,if a $ value is not add a self.estimated_weight_hd is used to get the total weight,
the code below should return a estimated_weight_total which can be used for the total sale price.
All works when I add the estimated_weight_total manually. I am lost as why.

def calc_estimated_weight_total(self):
if self.sale_head <= 0:
amount = (self.number * self.estimated_weight_hd)
return amount

def save(self):
self.estimated_total_weight = self.calc_estimated_weight_total()
super(SaleNote, self).save()

You'll have to be more informative than that.

Exactly what does "unable to get the following statement to work" mean?
What did you do to try to get it to work? What did you get instead? If
there was a traceback, please include it in an email.

While you're at it, please also tell us what version of Python, and on
what hardware you are running -- just in case that matters.

Gary Herron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top