python二分法查找程序
Program 1:
程序1:
a = 10
b = 3
res = a/b
print "a/b: ", res
res = float(a/b)
print "float (a/b) : ", res
res = float (a) /float (b)
print "float (a/b) : ", res
res = a/b
print "a/b: ", res
Output
输出量
a/b: 3float (a/b) : 3.0float (a/b) : 3.33333333333a/b: 3
Explanation:
说明:
The values of a and b are integer type.
a和b的值是整数类型。
Result of a/b will be an integer, thus the output of a/b will be 3.
a / b的结果将是一个整数,因此a / b的输出将为3 。
The statement float(a/b) will convert the result in float, a/b will be 3. Thus, float(a/b) = float(3) = 3.0. Output will be 3.0
语句float(a / b)将结果转换为float, a / b将为3 。 因此, float(a / b)= float(3)= 3.0 。 输出将是3.0
The statement float(a)/float(b)) will cast type the value of a and b and values will be 10.0 and 3.0. Thus the result of float(a)/float(b) will be 3.33333333333
语句float(a)/ float(b))将强制转换a和b的值,并且值将分别为10.0和3.0 。 因此float(a)/ float(b)的结果将为3.33333333333
The statement a/b returns the output without remainder i.e. the integer part of the result will be printed. Hence, he output will be 3.
语句a / b返回没有余数的输出,即将打印结果的整数部分。 因此,他的输出将为3 。
Program 2:
程式2:
a = 36.24
b = 24
res = a/b
print "a/b : ", res
res = (a//b)
print "(a//b) : ", res
Output
输出量
a/b : 1.51(a//b) : 1.0
Explanation:
说明:
Value of a is float, so there is no need to cast type a or b, the output will be in float.
的值是浮点数,所以没有必要铸型a或b时,输出将处于浮动。
Statement a/b will return the divide result. Thus, the output will be 1.51.
语句a / b将返回除法结果。 因此,输出将为1.51 。
Statement a//b will return only integer part of the result. Thus the output will be 1.0.
语句a // b将仅返回结果的整数部分。 因此输出将是1.0 。
翻译自: https://www.includehelp.com/python/find-output-of-python-programs-set-2-basics.aspx
python二分法查找程序