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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:計(jì)算收益和損失

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

創(chuàng)新互聯(lián)是一家專業(yè)提供定西企業(yè)網(wǎng)站建設(shè),專注與做網(wǎng)站、成都網(wǎng)站建設(shè)、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為定西眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。

寫一個(gè) Python 程序,用實(shí)例計(jì)算盈虧。

使用 Elif 語(yǔ)句計(jì)算收益和損失的 Python 程序

這個(gè) python 程序允許用戶輸入產(chǎn)品的銷售額和實(shí)際成本。接下來,Python 使用 Elif 語(yǔ)句基于這兩個(gè)值計(jì)算損失金額或利潤(rùn)金額。

# Python Program to Calculate Profit or Loss

actual_cost = float(input(" Please Enter the Actual Product Price: "))
sale_amount = float(input(" Please Enter the Sales Amount: "))

if(actual_cost > sale_amount):
    amount = actual_cost - sale_amount
    print("Total Loss Amount = {0}".format(amount))
elif(sale_amount > actual_cost):
    amount = sale_amount - actual_cost
    print("Total Profit = {0}".format(amount))
else:
    print("No Profit No Loss!!!")

Python 收益和損失輸出

 Please Enter the Actual Product Price: 1500
 Please Enter the Sales Amount: 1200
Total Loss Amount = 300.0

讓我試試不同的價(jià)值觀

Elif 聲明為

if(actual_cost > sale_amount):
    amount = actual_cost - sale_amount
    print("Total Loss Amount = {0}".format(amount))
elif(sale_amount > actual_cost):
    amount = sale_amount - actual_cost
    print("Total Profit = {0}".format(amount))
else:
    print("No Profit No Loss!!!")
  • If 條件檢查實(shí)際成本是否大于銷售金額。如果為真,則 Python 將損失金額打印為實(shí)際成本-銷售額
  • Elif 語(yǔ)句檢查銷售金額是否大于實(shí)際成本。如果為真,它會(huì)將利潤(rùn)額打印為銷售額-實(shí)際成本
  • 如果上述條件失敗,則意味著無利無損。

用算術(shù)運(yùn)算符計(jì)算盈虧的 Python 程序

在這個(gè)盈虧 python 程序中,我們使用的是一個(gè)減運(yùn)算符。

# Python Program to Calculate Profit or Loss

actual_cost = float(input(" Please Enter the Actual Product Price: "))
sale_amount = float(input(" Please Enter the Sales Amount: "))

if(actual_cost - sale_amount > 0):
    amount = actual_cost - sale_amount
    print("Total Loss Amount = {0}".format(amount))
elif(sale_amount - actual_cost > 0):
    amount = sale_amount - actual_cost
    print("Total Profit = {0}".format(amount))
else:
    print("No Profit No Loss!!!")

在這里,我們嘗試了所有的可能性,Python 盈虧程序的輸出是

 Please Enter the Actual Product Price: 2200
 Please Enter the Sales Amount: 6500
Total Profit = 4300.0
>>> 
 Please Enter the Actual Product Price: 9800
 Please Enter the Sales Amount: 7200
Total Loss Amount = 2600.0
>>> 
 Please Enter the Actual Product Price: 1495
 Please Enter the Sales Amount: 1495
No Profit No Loss!!!

網(wǎng)頁(yè)題目:Python程序:計(jì)算收益和損失
本文URL:http://www.5511xx.com/article/ccosogh.html