我有一個關於我的Python程序的問題。我無法在這個程序中找到總數和總數。休息工作正常。有什麼辦法可以解決這個問題嗎?我很快就有了這個計劃。我會很感激任何提示我可以得到:d感謝Python重複結構和文件
midSalary = 50000
maxSalary = 60000
def main():
inFile = open('program7.txt', 'r')
lineRead = inFile.readline()
total = 0.0
ntotal = 0.0
count = 0
while lineRead != '':
words = lineRead.split()
for word in words:
num = float(word)
total += num
count += 1
print("\nFaculty Member # ",count, ": $" , format(num, '.2f'), sep ="")
if num >= maxSalary:
payIncrease(num, .04)
elif num >= midSalary:
payIncrease(num, .07)
else:
payIncrease(num , .055)
lineRead = inFile.readline()
#averagePayRaise = (ntotal - total)/count
inFile.close()
for divider in range(45):
print("-", end ='')
print("\nTotal Faculty payroll : $", format(total , ",.2f"),sep ="")
print("The New Total Faculty payroll : $", format(ntotal , ",.2f"),sep ="")
print("Average Pay Raise : $", format(averagePayRaise, ",.2f"), sep ="")
def payIncrease(amount, prcnt):
print("Pay Raise Percent : ", format(prcnt*100, ".1f")+"%")
total = 0.0
ntotal = 0.0
count = 0
salRaise = amount * prcnt
newSal = amount + salRaise
print("Pay Raise : $", format(salRaise, ',.2f'), sep ="")
print("New Salary : $", format(newSal, ',.2f'), sep = "")
total += amount
count += 1
ntotal += newSal
averagePayRaise = (ntotal - total)/count
main()
我得到的解決方案爲0爲em – spuriousarbiter 2014-10-29 23:01:44
您能顯示輸入,預期輸出和當前輸出嗎? – 2014-10-29 23:04:38
共有教師工資:$ 1,310,555.15 新的總工資單系:$ 0.00 平均加薪:$ -59,570.69 我得到下面說 – spuriousarbiter 2014-10-29 23:06:45