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

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

新聞中心

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

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

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

寫一個 Python 程序,用實例計算盈虧。

使用 Elif 語句計算收益和損失的 Python 程序

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

# 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

讓我試試不同的價值觀

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 條件檢查實際成本是否大于銷售金額。如果為真,則 Python 將損失金額打印為實際成本-銷售額
  • Elif 語句檢查銷售金額是否大于實際成本。如果為真,它會將利潤額打印為銷售額-實際成本
  • 如果上述條件失敗,則意味著無利無損。

用算術運算符計算盈虧的 Python 程序

在這個盈虧 python 程序中,我們使用的是一個減運算符。

# 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!!!

本文標題:Python程序:計算收益和損失
網(wǎng)頁URL:http://m.5511xx.com/article/ccosogh.html