0

When I use variables print(f) = 0.0 and when I enter it by hand print(x) = 0.004285714285714276 which is what I want my variables to do. How do I get my variables to work like i need to?

pad = 109 / 100 + 1.0
dod = 100 / 119 + 1.0

per1 = 1.0 / pad * 100
per2 = 1.0 / dod * 100


b = pad - 1.0
p = per1/100
q = 1.0 - per1/100
f = (b * p - q)/b
print(f)
x = (0.84*0.54-0.45)/0.84
print(x)
Marcus
  • 5
  • 2
  • Did it not occur you to print out your intermedia variables? You're apparently using Python 2.x, in which case `/` performs integer division when given two integer operands. Specifically, `109 / 100` is being evaluated as zero, you'd have to write `109 / 100.0` or something similar to force floating-point division. – jasonharper Apr 25 '21 at 21:17
  • I am using python 3.9.1 – Marcus Apr 25 '21 at 21:19

1 Answers1

0

Because the math b*p equals to q

pad = 109 / 100 + 1.0
dod = 100 / 119 + 1.0

per1 = 1.0 / pad * 100
per2 = 1.0 / dod * 100


b = pad - 1.0
p = per1/100
q = 1.0 - per1/100
f = (b * p - q)/b
print(f'b*p:{b*p},q:{q}')
# b*p:0.5215311004784688,q:0.5215311004784688
x = (0.84*0.54-0.45)/0.84
print(x)

DevScheffer
  • 491
  • 4
  • 15