Home > other >  In python calculating equation for 2 yuan 1 time, the use of np, arrange, no results
In python calculating equation for 2 yuan 1 time, the use of np, arrange, no results

Time:10-26

 
For a np in arange (1, 10, 0.1) :
A for b in np. Arange (1, 10, 0.1) :
If a * 2 + b * 3==18.00:
Print (a, b)


Only integer code as above, the theory is the result, but is allowed after the decimal, there is no result

CodePudding user response:

Floating point types of precision problem, computer storage floating-point number is error, when comparing floating-point Numbers usually does not directly using the==comparison,

Other python provides calculation and high precision method, such as:
 
The import numpy as np
The from fractions import Fraction
For a np in arange (1, 10, Fraction (1, 10)) :
For b in np. Arange (1, 10, Fraction (1, 10)) :
If a * b * 2 + 2==Fraction (18) :
Print (float (a), the float (b))