#global variable
CONTRIBUTION_RATE = 0.05
def main():
#if these are set to 0 they do not calculate contribution but it does run the program.
grossPay = 0
bonusPay = 0
#gets gross pay from input
GetGrossPay(grossPay)
#gets bonus pay from input
GetBonusPay(bonusPay)
#takes input from GetGrossPay to calculate contrib
showGrossPayContrib(grossPay)
#takes input from GetBonusPay to calculate contrib
showBonusContrib(bonusPay)
#This will prompt user to enter gross pay
def GetGrossPay(grossPay):
grossPay = float(input("Enter the total gross pay: "))
return grossPay
#This will prompt user to enter bonus pay
def GetBonusPay(bonusPay):
bonusPay = float(input("Enter the total bonus pay: "))
return bonusPay
#This SHOULD take the grossPay from GetGrossPay module to get GrossPayContrib
def showGrossPayContrib(theGrossPay):
theGrossPay = CONTRIBUTION_RATE * theGrossPay
print("The contribution for the gross pay is $ ",theGrossPay)
#This SHOULD take the bonusPay from GetBonusPay module to get BonusContrib
def showBonusContrib(theBonus):
theBonus = CONTRIBUTION_RATE * theBonus
print("The contribution for the bonuses is $ ",theBonus)
main()
1
A
回答
0
應該是你要找的。試試這個
#global variable
CONTRIBUTION_RATE = 0.05
def main():
gross = GetGrossPay()
bonus = GetBonusPay()
sum = GetSumContribution(gross, bonus)
showGrossPayContrib(gross)
showBonusContrib(bonus)
showSumContrib(sum)
def GetGrossPay():
#as it stands there is no reason to pass a variable in
return float(input("Enter the total gross pay: "))
def GetBonusPay():
return float(input("Enter the total bonus pay: "))
def GetSumContribution(gross, bonus):
return sum((gross*CONTRIBUTION_RATE, bonus*CONTRIBUTION_RATE))
def showGrossPayContrib(theGrossPay):
theGrossPay = CONTRIBUTION_RATE * theGrossPay
print("The contribution for the gross pay is $ ",theGrossPay)
def showBonusContrib(theBonus):
theBonus = CONTRIBUTION_RATE * theBonus
print("The contribution for the bonuses is $ ",theBonus)
def showSumContrib(sumContrib):
print("The sum of the Bonus and Gross contributions is ${}".format(sumContrib))
main()
+0
是的!謝謝,好的,我將把這個例子應用到我的下一個場景中,並且如果我需要進一步的幫助,將會更新!你真的幫助我了! – Alina
+0
歡迎您! – TheLazyScripter
+0
好的,我在下一個場景中確實需要幫助。我仍然使用上面的例子。如果我想從總額和獎金中找到貢獻的總和,我怎麼能夠在那裏添加該模塊? – Alina
相關問題
- 1. Woocommerce根據客戶在產品頁面輸入的金額計算金額
- 2. 腳本根據存款和取款計算賬戶餘額
- 3. 使用F#計量單位從淨額+增值稅金額中計算毛額
- 4. 如何根據用戶輸入使某個代碼塊運行?
- 5. 根據付款金額註冊日期
- 6. 需要用戶輸入口令代碼
- 7. XSL - 計算金額之和
- 8. 需要幫助,試圖根據用戶輸入計算平均值。 C
- 9. 貝寶付款取決於其他用戶支付全部金額的份額?
- 10. 使用mysql查詢計算提款日期前的總金額
- 11. 用django計算每日獎金
- 12. 計算贏/輸,贏得比例和總獎金
- 13. 根據用戶輸入計算一天:總是返回當天
- 14. 如何根據需要導入模塊的某些部分?
- 15. 根據交易計算最低帳單金額的算法
- 16. c#計算金額
- 17. 計算總金額
- 18. 根據現場輸入計算總和
- 19. OpenERP 7.0人力資源費用模塊到期金額計算
- 20. 輸入貸款金額和年數。上表顯示的利息,每月還款金額和我有下面的代碼問題支付總額
- 21. 計算所需更改的金額
- 22. 一旦用戶輸入金額,金額應乘以「s2」
- 23. 根據yii2中輸入的值更新金額和總字段
- 24. 計算累計佣金額
- 25. 用金額閾值計算佣金
- 26. 通過js使用金額和折扣計算總額?
- 27. 錯誤在我的獎金計算器
- 28. 獲得獎金支付計算
- 29. 用美分顯示全部美元金額的輸入框
- 30. ERP中的付款輸入/收據未付金額下一個
你能格式化你的代碼嗎?幾乎不可能以文本傷害我的眼睛的方式來幫助你... –
嗨,Alina,歡迎來到Stack Overflow。請閱讀[問]。 –
Alina ...只有在你的代碼中缺少的東西是它沒有捕獲主要從其他函數返回的值。請檢查此鏈接以獲得幫助https://learnpythonthehardway.org/book/ex21.html –