Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def validate _ float _ input ( prompt ) : dots,main ( ) . . . Enter employee names and salaries. Type 'DONE' when finished.
def validatefloatinputprompt: dots,main
Enter employee names and salaries. Type 'DONE' when finished.
Enter employee name or DONE to finish: Tom
Enter employee salary in thousands eg for :
Employee: Tom, Salary: $
Enter employee name or DONE to finish: Martha
Enter employee salary in thousands eg for :
Employee: Martha, Salary: $
Enter employee name or DONE to finish: Teddy
Enter employee salary in thousands eg for :
Employee: Teddy, Salary: $
Enter employee name or DONE to finish: Fred Flintstone
Enter employee salary in thousands eg for :
Employee: Fred Flintstone, Salary: $
Enter employee name or DONE to finish: Red Runner
Enter employee salary in thousands eg for :
Employee: Red Runner, Salary: $
Enter employee name or DONE to finish: Gerdy Anderson
Enter employee salary in thousands eg for :
Employee: Gerdy Anderson, Salary: $
Enter employee name or DONE to finish: DONE
Average Salary: $
Employees with salaries within $ of the average:
Name: Teddy, Salary: $
Name: Fred Flintstone, Salary: $
Name: Gerdy Anderson, Salary: $
while True:
try:
value floatinputprompt
return value
except ValueError:
printInvalid input. Please enter a valid floating point number."
def main:
names
salaries
sentinel 'DONE'
printEnter employee names and salaries. Type 'DONE' when finished."
while True:
name inputEnter employee name or DONE to finish:
if name sentinel:
break
salary validatefloatinputEnter employee salary in thousands eg for :
names.appendname
salaries.appendsalary
if lensalaries:
printNo valid employee data entered."
return
averagesalary sumsalaries lensalaries
printf
Average Salary: $averagesalary :f
print
Employees with salaries within $ of the average:"
withinrange False
for name, salary in zipnames salaries:
if abssalary averagesalary:
printfName: name Salary: $salary :f
withinrange True
if not withinrange:
printNo employees have salaries within $ of the average."
if namemain:
main
The code above prints out the average salary and also those within a range of it So I almost have it but the last thing I need is to display every entere I've attached a copy of the current output.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started