# 循环进行Python编码

def avgSalary（EmpWages）：     “”“查找平均工资的函数”“”     ＃最初将合计设置为0     总数= 0;

``````# Iterating over array
for i in range(0, len(EmpWages)):
# Accumulating value
total += EmpWages[i];
# Finding and returning average
return (total / float(len(EmpWages)));
``````

def printData（EmpNames，EmpWages）：     “”“函数将员工姓名和工资打印到控制台”“”     ＃打印标题     print（“ \ n \ n％-20s％-20s \ n”％（“员工姓名”，“员工工资”））；     ＃遍历数组     对于范围内的我（0，len（EmpNames））：         ＃印刷价值         print（“ \ n％-20s％-20.2f”％（EmpNames [i]，EmpWages [i]））;     ＃打印平均工资     print（“ \ n \ n平均工资：％.2f \ n \ n”％（avgSalary（EmpWages）））;

``````# Reading five employee's details
for i in range(1, 6):
name = input("\n Enter Employee Name or DONE to Finish: ");

# Iterate till user enters a valid salary
while True:
try:
wage = float(input("\n Enter Employee Salary or DONE to Finish: "));
break;
except:
print("\n Invalid Value!!! \n");

EmpNames.append(name);
EmpWages.append(wage);
``````

def main（）：     “”         读取员工姓名并找到平均工资的Python程序     “”     ＃包含名称的列表     EmpNames = [];

``````# List that holds wages
EmpWages = [];

# Reading names and wages from user