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

寫一個 Python 程序,用算術運算符和函數(shù)計算一個數(shù)的立方,并舉例說明。
尋找數(shù)字立方體的 Python 程序
這個 Python 程序允許用戶輸入任何數(shù)值。接下來,Python 使用算術運算符找到該數(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))一個數(shù)字輸出的 Python 立方體
Please Enter any numeric Value : 5
The Cube of a Given Number 5.0 = 125.0計算數(shù)字立方的 Python 程序示例 2
這個 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 程序
在這個 Python 程序的立方體編號代碼片段中,我們定義了一個函數(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)) 分享文章:Python程序:計算數(shù)字立方
文章路徑:http://m.5511xx.com/article/dhdejgd.html


咨詢
建站咨詢
