break和continue练习
# 输入员工薪资,如果输入薪资<0,则重新输入,最后打印出员工人数和薪资明细,以及平均薪资
empNum = 0
salarySum = 0
salaries = []
while True:
s = input("请输入员工的薪资(按Q或者q结束:)")
if s.upper() == "Q":
print("录入完成,退出")
break
if float(s)<0:
continue
empNum += 1
salaries.append(float(s))
salarySum += float(s)
print("打印出员工人数{0}:".format(empNum))
print("打印出薪资明细{0}:".format(salarySum))
print("打印出平均薪资{0}".format(salarySum/empNum))
print("录入薪资:",salaries)
else练习:
# 输入4个员工薪资,全部录入后,打印提示:您已经全部录入4名员工薪资,最后打印出员工人数和薪资明细,以及平均薪资
empNum = 0
salaryNum = 0
salaries = []
for x in range(4):
s = input("请输入员工的薪资(按Q或者q结束:)")
if s.upper() == 'Q':
break
print("结束录入薪资")
if float(s)<0:
continue
empNum +=1
salaries.append(float(s))
salaryNum += float(s)
else:
print("您已经全部录入4名员工薪资")
print("输入员工总人数:",empNum)
print("打印薪资明细:",salaries)
print("打印员工平均薪资{0}".format(salaryNum/empNum))