日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:簡單相加兩個(gè)數(shù)字

創(chuàng)新互聯(lián)Python教程:

成都創(chuàng)新互聯(lián)是一家從事企業(yè)網(wǎng)站建設(shè)、成都做網(wǎng)站、網(wǎng)站制作、行業(yè)門戶網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)制作的專業(yè)網(wǎng)站設(shè)計(jì)公司,擁有經(jīng)驗(yàn)豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁設(shè)計(jì)人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實(shí)力,在網(wǎng)站建設(shè)領(lǐng)域樹立了自己獨(dú)特的設(shè)計(jì)風(fēng)格。自公司成立以來曾獨(dú)立設(shè)計(jì)制作的站點(diǎn)1000+。

用例子寫一個(gè)簡單的 Python 程序。為了演示,我們將使用算術(shù)運(yùn)算符將兩個(gè)數(shù)字相加

簡單的 Python 程序相加兩個(gè)數(shù)字

這個(gè)簡單的 Python 程序相加了兩個(gè)數(shù)字,允許用戶輸入兩個(gè)值。接下來,它將把這兩個(gè)數(shù)字相加,并將總和賦給變量 sum。

number1 = input(" Please Enter the First Number: ")
number2 = input(" Please Enter the second number: ")

# Using arithmetic + Operator to add two numbers
sum = float(number1) + float(number2)
print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))

Python 相加兩個(gè)數(shù)字輸出

 Please Enter the First Number: 22
 Please Enter the second number: 44
The sum of 22 and 44 is 66.0

在這個(gè)相加兩個(gè)數(shù)字的簡單 python 程序示例中,以下語句要求用戶輸入兩個(gè)整數(shù),并將用戶輸入的值存儲(chǔ)在變量 1 和 2 中

number1 = input(" Please Enter the First Number: ")
number2 = input(" Please Enter the second number: ")

下一行,我們使用 Python 算術(shù)運(yùn)算符“+”將數(shù)字 1 和數(shù)字 2 相加,然后將該總和賦給 sum。

從下面的語句中,您可以看到,我們使用 float type cast 將用戶輸入值轉(zhuǎn)換為 float。這是因?yàn)椋J(rèn)情況下,用戶輸入的值是字符串類型的,如果我們在兩個(gè)字符串值之間使用+運(yùn)算符,python 會(huì)連接這兩個(gè)值,而不是相加它們

sum = float(number1) + float(number2)

下面的 Python 打印語句將輸出 sum 變量(22 + 44 = 66)。

print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))

這個(gè) python 程序在加兩個(gè)正整數(shù)的時(shí)候加兩個(gè)數(shù)字效果很好,加正負(fù)整數(shù)怎么樣?讓我們看看

相加兩個(gè)數(shù)字的示例 Python 程序示例 2

負(fù)數(shù)也沒問題!。編寫上述 python 相加兩個(gè)數(shù)字程序的替代方法是:

number1 = float(input(" Please Enter the First Number: "))
number2 = float(input(" Please Enter the second number: "))

# Using arithmetic + Operator to add two numbers
sum = number1 + number2
print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))
 Please Enter the First Number: 25
 Please Enter the second number: 91
The sum of 25.0 and 91.0 is 116.0

注:以上簡單的程序?qū)⑾拗朴脩?,不輸入字符串值作為輸?/p>
當(dāng)前標(biāo)題:Python程序:簡單相加兩個(gè)數(shù)字
本文地址:http://m.5511xx.com/article/dhochsj.html