Search code examples
pythonmathnumericnumerical-methodspointer-arithmetic

Why the the arithmetic of python always return 10 for this function?


The output for this code is always 10. AM I doing something wrong? I also want assistance the negative rational exponent equation for "Vc"

let R=10000, C=1e-6, and Vs=10

   R= 10000
   C= 10**-6
   Vs= 10
   T= float(R*C)
   t= float(input("Enter the value of t:"))
   Vc=Vs*(1-(10**-(t/T)))
   print(format(Vc,".5f"))

Thank you in advance for your replies.


Solution

  • You don't always get 10. For small numbers, you get a value other than 10. Try entering .0001, for example.

    For larger values of t, the expression 10**-(t/T) is so small a number that Python treats it as 0. So you have 10*(1-0), or 10, for large enough values of t. 1 is too large, so you do get 10 for an entry of 1, and anything bigger than that. -1, btw, gives an interesting answer, and entering a large negative value crashes the program with an overflow error.