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

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供成都做網(wǎng)站、網(wǎng)站制作服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。創(chuàng)新互聯(lián)建站將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。
用實例編寫 Python 程序計算電費。為此,我們使用了 Elif 語句。
計算電費的 Python 程序示例 1
這個 python 程序允許用戶輸入用戶消耗的單位。接下來,Python 計算總電費。如果電力局對不同的設(shè)備收取不同的費用,這種方法是有用的。對于這個例子,我們使用的是 Elif 語句。
# Python Program to Calculate Electricity Bill
units = int(input(" Please enter Number of Units you Consumed : "))
if(units < 50):
amount = units * 2.60
surcharge = 25
elif(units <= 100):
amount = 130 + ((units - 50) * 3.25)
surcharge = 35
elif(units <= 200):
amount = 130 + 162.50 + ((units - 100) * 5.26)
surcharge = 45
else:
amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
total = amount + surcharge
print("\nElectricity Bill = %.2f" %total)Python 程序查找電費示例 2
如果電路板具有統(tǒng)一的速率,則該 Python 代碼非常有用。類似于:如果你消耗 300 到 500 個單位,那么單位固定為 7.75 盧比,等等。讓我們看看 python 程序
提示: Elif 語句先檢查蟒的情況。如果為真,則執(zhí)行該塊中的語句。如果條件為假,則 python 程序檢查下一個條件(Elif 條件)等等。
# Python Program to Calculate Electricity Bill
units = int(input(" Please enter Number of Units you Consumed : "))
if(units > 500):
amount = units * 9.65
surcharge = 85
elif(units >= 300):
amount = units * 7.75
surcharge = 75
elif(units >= 200):
amount = units * 5.26
surcharge = 55
elif(units >= 100):
amount = units * 3.76
surcharge = 35
else:
amount = units * 2.25
surcharge = 25
total = amount + surcharge
print("\nElectricity Bill = %.2f" %total)蟒電程序輸出
Please enter Number of Units you Consumed : 450
Electricity Bill = 3562.50
>>>
Please enter Number of Units you Consumed : 750
Electricity Bill = 7322.50
>>>
Please enter Number of Units you Consumed : 250
Electricity Bill = 1370.00
>>>
Please enter Number of Units you Consumed : 150
Electricity Bill = 599.00
>>>
Please enter Number of Units you Consumed : 50
Electricity Bill = 137.50 新聞名稱:Python 程序:計算電費
新聞來源:http://www.5511xx.com/article/cdoicgc.html


咨詢
建站咨詢
