PDA

View Full Version : Problem with python coding


toggers
05-27-2006, 08:49 AM
Hi, this is probably a really simple problem for you guys, but i've only just started programming in python, and i've come across this problem. i'm trying to calculate the sales cost of a product by getting values from two text boxes and doing that maths equation to display the answer in a label

I'm using the program "Eric" in python to program the file, and i'm using "PyQT to design the form.

This is my code (under the function "calculate sales cost):
f = str(self.txtOriginal_cost.text())
g = str(self.txtDiscount.text.text())
h = float(f - (f / 100 * g))

self.lblCost.setText(h)
_________________________________________________________________

If someone could give me an answer as soon as possible that would be great!

Thanks

ghostdog74
05-27-2006, 03:35 PM
Hi, this is probably a really simple problem for you guys, but i've only just started programming in python, and i've come across this problem. i'm trying to calculate the sales cost of a product by getting values from two text boxes and doing that maths equation to display the answer in a label

I'm using the program "Eric" in python to program the file, and i'm using "PyQT to design the form.

This is my code (under the function "calculate sales cost):
f = str(self.txtOriginal_cost.text())
g = str(self.txtDiscount.text.text())
h = float(f - (f / 100 * g))

self.lblCost.setText(h)
_________________________________________________________________

If someone could give me an answer as soon as possible that would be great!

Thanks

f and g are both strings, after you did str(...)
and you would get error when you did a string (f) by 100
change your data type for f,g before you do arithmetic

toggers
05-28-2006, 12:25 AM
would you be able to suggest a solution?

ghostdog74
05-28-2006, 08:09 AM
would you be able to suggest a solution?
try converting your f and g to integers using integers or floats , not strings. Then you can do the maths