Python 需要使代码全部模块化。目标是根据用户输入计算总收入和奖金贡献
应该是你要找的。试试这个Python 需要使代码全部模块化。目标是根据用户输入计算总收入和奖金贡献,python,python-3.x,module,global-variables,Python,Python 3.x,Module,Global Variables,应该是你要找的。试试这个 #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)
#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()
应该是你要找的。试试这个
#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()
你能格式化你的代码吗?这是几乎不可能帮助你的方式,文字伤害我的眼睛…嗨,艾琳娜,欢迎堆栈溢出。请读,艾琳娜。。。代码中唯一缺少的是它没有捕获main中的值,而main是从其他函数返回的。请检查此链接以获取帮助。您可以格式化代码吗?这是几乎不可能帮助你的方式,文字伤害我的眼睛…嗨,艾琳娜,欢迎堆栈溢出。请读,艾琳娜。。。代码中唯一缺少的是它没有捕获main中的值,而main是从其他函数返回的。请检查此链接以获取帮助是!谢谢,好的,我将把这个例子应用到我的下一个场景中,如果我需要进一步的帮助,我将进行更新!你真的帮了我大忙!!好的,我在下一个场景中需要帮助。我仍将使用上面的示例。如果我想从总额和奖金中找到供款总额,我如何才能将该模块添加到其中?@Alina Updated,如果我理解正确,请告诉我您的第一次编辑没有问题,它将提示输入总额和奖金。当程序运行时,它将输出每个项目的贡献。如何按顺序显示:输入总薪酬、输入奖金薪酬、输出总贡献、输出奖金贡献、输出总贡献和奖金(这是唯一缺少的部分)。我将如何计算总薪酬分摊模块和奖金分摊模块计算出的值,以将它们相加到它自己的模块中?我将在可能时更新您。我不得不离开我的电脑。我真的很感谢你的帮助!对谢谢,好的,我将把这个例子应用到我的下一个场景中,如果我需要进一步的帮助,我将进行更新!你真的帮了我大忙!!好的,我在下一个场景中需要帮助。我仍将使用上面的示例。如果我想从总额和奖金中找到供款总额,我如何才能将该模块添加到其中?@Alina Updated,如果我理解正确,请告诉我您的第一次编辑没有问题,它将提示输入总额和奖金。当程序运行时,它将输出每个项目的贡献。如何按顺序显示:输入总薪酬、输入奖金薪酬、输出总贡献、输出奖金贡献、输出总贡献和奖金(这是唯一缺少的部分)。我将如何计算总薪酬分摊模块和奖金分摊模块计算出的值,以将它们相加到它自己的模块中?我将在可能时更新您。我不得不离开我的电脑。我真的很感谢你的帮助!