Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def validate _ float _ input ( prompt ) : dots,main ( ) . . . Enter employee names and salaries. Type 'DONE' when finished.

def validate_float_input(prompt): dots,main()
...
Enter employee names and salaries. Type 'DONE' when finished.
Enter employee name (or DONE to finish): Tom
Enter employee salary in thousands (e.g.,24.5 for 24500): 65.5
Employee: Tom, Salary: $65500.00
Enter employee name (or DONE to finish): Martha
Enter employee salary in thousands (e.g.,24.5 for 24500): 24.5
Employee: Martha, Salary: $24500.00
Enter employee name (or DONE to finish): Teddy
Enter employee salary in thousands (e.g.,24.5 for 24500): 50
Employee: Teddy, Salary: $50000.00
Enter employee name (or DONE to finish): Fred Flintstone
Enter employee salary in thousands (e.g.,24.5 for 24500): 49.5
Employee: Fred Flintstone, Salary: $49500.00
Enter employee name (or DONE to finish): Red Runner
Enter employee salary in thousands (e.g.,24.5 for 24500): 55
Employee: Red Runner, Salary: $55000.00
Enter employee name (or DONE to finish): Gerdy Anderson
Enter employee salary in thousands (e.g.,24.5 for 24500): 44.5
Employee: Gerdy Anderson, Salary: $44500.00
Enter employee name (or DONE to finish): DONE
Average Salary: $48166.67
Employees with salaries within $5000 of the average:
Name: Teddy, Salary: $50000.00
Name: Fred Flintstone, Salary: $49500.00
Name: Gerdy Anderson, Salary: $44500.00
>
while True:
try:
value = float(input(prompt))
return value
except ValueError:
print("Invalid input. Please enter a valid floating point number.")
def main():
names =[]
salaries =[]
sentinel = 'DONE'
print("Enter employee names and salaries. Type 'DONE' when finished.")
while True:
name = input("Enter employee name (or DONE to finish): ")
if name == sentinel:
break
salary = validate_float_input("Enter employee salary in thousands (e.g.,24.5 for 24500): ")
names.append(name)
salaries.append(salary)
if len(salaries)==0:
print("No valid employee data entered.")
return
average_salary = sum(salaries)/ len(salaries)
print(f"
Average Salary: ${average_salary *1000:.2f}")
print("
Employees with salaries within $5000 of the average:")
within_range = False
for name, salary in zip(names, salaries):
if abs(salary - average_salary)=5:
print(f"Name: {name}, Salary: ${salary *1000:.2f}")
within_range = True
if not within_range:
print("No employees have salaries within $5000 of the average.")
if __name__=='__main__':
main()
The code above prints out the average salary and also those within a 5000 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

2. Write two or three of your greatest weaknesses.

Answered: 1 week ago