Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def validate _ float _ input ( prompt ) : while True: try: value = float ( input ( prompt ) ) return value except

def validate_float_input(prompt):
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 entered employee and their salary added under the text Employee and Salary Entered.

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions