新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:計(jì)算數(shù)字立方
創(chuàng)新互聯(lián)python教程:

寫一個(gè) Python 程序,用算術(shù)運(yùn)算符和函數(shù)計(jì)算一個(gè)數(shù)的立方,并舉例說(shuō)明。
尋找數(shù)字立方體的 Python 程序
這個(gè) Python 程序允許用戶輸入任何數(shù)值。接下來(lái),Python 使用算術(shù)運(yùn)算符找到該數(shù)字的立方體。
# Python Program to Calculate Cube of a Number
number = float(input(" Please Enter any numeric Value : "))
cube = number * number * number
print("The Cube of a Given Number {0} = {1}".format(number, cube))一個(gè)數(shù)字輸出的 Python 立方體
Please Enter any numeric Value : 5
The Cube of a Given Number 5.0 = 125.0計(jì)算數(shù)字立方的 Python 程序示例 2
這個(gè) Python 立方數(shù)的例子同上,但是在這里,我們使用的是指數(shù)算子。
# Python Program to Calculate Cube of a Number
number = float(input(" Please Enter any numeric Value : "))
cube = number ** 3
print("The Cube of a Given Number {0} = {1}".format(number, cube)) Please Enter any numeric Value : 10
The Cube of a Given Number 10.0 = 1000.0用函數(shù)求數(shù)字立方體的 Python 程序
在這個(gè) Python 程序的立方體編號(hào)代碼片段中,我們定義了一個(gè)函數(shù),它可以找到給定數(shù)字的立方體。
# Python Program to Calculate Cube of a Number
def cube(num):
return num * num * num
number = float(input(" Please Enter any numeric Value : "))
cub = cube(number)
print("The Cube of a Given Number {0} = {1}".format(number, cub)) 當(dāng)前標(biāo)題:Python程序:計(jì)算數(shù)字立方
分享網(wǎng)址:http://fisionsoft.com.cn/article/dhdejgd.html


咨詢
建站咨詢
