2016-09-11 19 views
1
#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() 
+0

你能格式化你的代碼嗎?幾乎不可能以文本傷害我的眼睛的方式來幫助你... –

+0

嗨,Alina,歡迎來到Stack Overflow。請閱讀[問]。 –

+0

Alina ...只有在你的代碼中缺少的東西是它沒有捕獲主要從其他函數返回的值。請檢查此鏈接以獲得幫助https://learnpythonthehardway.org/book/ex21.html –

回答

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