Ich bekomme Null als Rendite für Gehalt. Ich weiß, dass es vielleicht mit variablem Umfang zu tun hat, aber ich bin verloren.Wie erstelle ich eine Funktion in Python, die jedes Mal in einer While-Schleife akkumuliert
'''
Write a program to declare two empty lists one is for name and one for salaries.
Within the for loop ask for employees name and their salaries
and append them into the list accordingly.
Find out the total salary using accumulation concept but you
need to call a function called EvaluateSalary() within the for loop passing the argument
salary for each iteration.
Output : Both of the lists with their items and the total salary.
'''
#Declare name list
nameList = []
#declare salary list
salaryList = []
#declare quit constant
QUIT = "ZZZ" or 000
employeeName = str(input("Please enter an Employee name or ZZZ to quit : ")).upper()
employeeSalary = float(input("Please enter the salary of the Employee or 000 to quit : "))
Unten ist, was ich nicht richtig mache. Ich möchte, dass die Gehaltseingabe durch jeden Durchlauf der Schleife hinzugefügt wird.
salary = 0
def EvaluateSalary(salary):
salary = salary + employeeSalary
return salary
while employeeName != QUIT:
nameList.append(employeeName)
salaryList.append(employeeSalary)
EvaluateSalary(salary)
employeeName = str(input("Please enter an Employee name or ZZZ to quit : ")).upper()
employeeSalary = float(input("Please enter the salary of the Employee or 000 to quit : "))
print("Goodbye!")
print(nameList, salaryList, salary)
dies nicht Python ist, den Code eingerückt werden muss richtig – Pykler
zu arbeiten ist. Ich weiß einfach nicht, wie man hier richtig schreibt –
Es wurde meinen Code –