新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:求兩個浮點數(shù)的和
創(chuàng)新互聯(lián)Python教程:

python 中如何求浮點數(shù)的和?
總和是我們在日常生活中所做的基本數(shù)學運算之一。加減乘除是數(shù)學中的基本運算。所以在這個簡單的 python 程序中,我們在做兩個浮點數(shù)的和。
浮點數(shù)是雙精度數(shù)字。例如,73.45 是一個浮點數(shù),12.34 是另一個浮點數(shù)。我們必須計算這兩個數(shù)字的總和。'73.45 + 12.34 = 85.79'.
在這個 Python 程序中,我們接受來自用戶的兩個值,并使用“int”函數(shù)將這些值轉換為整數(shù)。使用變量和 和計算這兩個float點號的和。最后用 Python 語言的打印功能顯示和。
算法
步驟 1: 使用 python 編程語言中的輸入函數(shù)接受用戶值。使用float數(shù)據(jù)類型將字符串值轉換為浮點數(shù),并將數(shù)字保存在變量中。
步驟 2: 將用戶使用 python 中的sum‘+’運算符輸入的數(shù)字相加。請注意,在將結果添加到另一個變量中并保存時,請使用浮點數(shù)據(jù)類型。
步驟 3: 使用print功能顯示結果。
Python 源代碼
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: ")) #accpeting and converting the string to float and save in vaiable
sum = num1 + num2 # doing the addition using '+' operator
print("The sum is: ", sum) # display the result of the sum
輸出
Enter the first number: 80.60
Enter the second number: 20.40
The sum is: 101.00 網(wǎng)站題目:Python程序:求兩個浮點數(shù)的和
網(wǎng)頁路徑:http://fisionsoft.com.cn/article/dpcjhgo.html


咨詢
建站咨詢
