Alina - 1 year ago 65
Python Question

# 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()

The issue is that you never overwrite the value of `grosspay` and `bonuspay`. Here's how you do that!

``````#global variable
CONTRIBUTION_RATE = 0.05

def main():
showGrossPayContrib(GetGrossPay())#no reason to pre-define either bonus or gross
showBonusContrib(GetBonusPay())

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 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)

main()
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download