1

How do I add together predefined functions that get a value from an entry?

what I want is the total value of all these, but it will only add them if all are true. what I want is it to add even if one is false.

#The Problem def TotalCost(): qty1= eVal1() qty2= eVal2() qty3= eVal3() qty4= eVal4() qty5= eVal5() qty6= eVal6() qty7= eVal7() qty8= eVal8() qty9= eVal9() totalsum= qty1+qty2+qty3+qty4+qty5+qty6+qty7+qty8+qty9 if totalsum >0: Total.delete(0, END) Total.insert(0, "%.2f" % totalsum) return totalsum 

Entrys its taking from.

Functions and definitions

value1= IntVar() value2= IntVar() value3= IntVar() value4= IntVar() value5= IntVar() value6= IntVar() value7= IntVar() value8= IntVar() value9= IntVar() value10= IntVar() #Gets Value from entry and gives total def eVal1(): a= value1.get() doughnut = "Strawberry" + " X" results1 = doughnut + str(a) if a>0: b= a*0.99 List1.insert(0, results1) return b def eVal2(): c= value2.get() doughnut = "Custard" + " X" results2 = doughnut + str(c) if c>=0: d= c*0.99 List1.insert(0, results2) return d def eVal3(): e= value4.get() doughnut = "Sugar Ring" + " X" results3 = doughnut + str(e) if e>=0: f= e*0.99 List1.insert(0, results3) return f def eVal4(): g= value5.get() doughnut = "Chocolate Caramel" + " X" results4 = doughnut + str(g) if g>=0: h= g*0.99 List1.insert(0, results4) return h def eVal5(): i= value6.get() doughnut = "Lemon Circle" + " X" results5 = doughnut + str(i) if i>=0: j= i*0.99 List1.insert(0, results5) return j def eVal6(): k= value7.get() doughnut = "Blueberry Blaster" + " X" results6 = doughnut + str(k) if k>=0: l= k*0.99 List1.insert(0, results6) return l def eVal7(): m= value8.get() doughnut = "Strawberry Suprise" + " X" results7 = doughnut + str(m) if m>=0: n= m*0.99 List1.insert(0, results7) return n def eVal8(): o= value9.get() doughnut = "Simple Sugar" + " X" results8 = doughnut + str(o) if o>=0: p= o*0.99 List1.insert(0, results8) return p def eVal9(): q= value10.get() doughnut = "Apple Cinnamon" + " X" results9 = doughnut + str(q) if q>=0: r= q*0.99 List1.insert(0, results9) return r 

Error message

line 164, in TotalCost totalsum= qty1+qty2+qty3+qty4+qty5+qty6+qty7+qty8+qty9 TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'

2
  • What do you mean by true and false in the question? Commented May 23, 2015 at 18:35
  • all the get boxes must have a value for it to add together. or it fails. qty1+qty2+qty3+qty4+qty5+qty6+qty7+qty8+qty9 if one of these doesnt contain a number it gets errors. more specific qty1 ...... errors are these line 164, in TotalCost totalsum= qty1+qty2+qty3+qty4+qty5+qty6+qty7+qty8+qty9 TypeError: unsupported operand type(s) for +: 'NoneType' and 'float' Commented May 23, 2015 at 18:40

1 Answer 1

2

In all the eVal functions, you can add an else condition and return 0 in else block.

Ex:

def eVal1(): a= value1.get() doughnut = "Strawberry" + " X" results1 = doughnut + str(a) if a>0: b= a*0.99 List1.insert(0, results1) return b else: return 0 

Similarly, add it in all the eVal functions.

Sign up to request clarification or add additional context in comments.

1 Comment

Edited the answer to include example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.