python二分法查找程序_查找Python程序的输出| 套装2(基础)
python二分法查找程序
Program 1:
程序1:
a = 10 b = 3res = 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: ", resOutput
輸出量
a/b: 3float (a/b) : 3.0float (a/b) : 3.33333333333a/b: 3Explanation:
說明:
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) : ", resOutput
輸出量
a/b : 1.51(a//b) : 1.0Explanation:
說明:
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二分法查找程序
總結
以上是生活随笔為你收集整理的python二分法查找程序_查找Python程序的输出| 套装2(基础)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 数据库编码,php怎么设置数据库
- 下一篇: echarts 柱状图不显示y坐标轴_P