#Lists storing the employee names and salaries
listofemployeenames = []
listofemployeesalaries = []
#Taking employee names
emp_name= input("What is the employee's name?")
emp_name.append(listofemployeenames)
#Taking employee salaries
emp_sal = float(input("What is the employee's salary?"))
emp_sal.append(listofemployeesalaries)
#Finding the average of all the salaries
avg_sal = sum(listofemployeesalaries)/len(listofemployeesalaries)
#Printing out the names of employees with salaries within 5k of the average
print("Name\t||\tSalary", end='\n\n')
for i in range(len(emp_sal)):
if emp_sal[i]>= avg_sal-5 and emp_sal[i]<=avg_sal+5:
print(f'{emp_name[i]} \t||\t {emp_sal[i]}')
#How to print of a list of employee salaries within 5000 of average of one while accepting user input
16 messages · Page 1 of 1 (latest)
you haven't said what problem you are having but you have your appends the wrong way round. It should be list.append(some_value)
You have some_value.append(list)
@gentle geode
thanks for the feedback. Im going to change it and rethink my question to you
When I run the program I get the error float has no len. im trying to get the average
@gentle geode
Griffin Uploaded Some Code
Attachment: message.txt
```py
#Lists storing the employee names and salaries
listofemployeenames = []
listofemployeesalaries = []
#Taking employee names
emp_name= input("What is the employee's name?")
listofemployeenames.append(emp_name)
#Taking employee salaries
emp_sal = float(input("What is the employee's salary?"))
listofemployeesalaries.append(emp_sal)
#Finding the average of all the salaries
avg_sal = sum(listofemployeesalaries)/len(listofemployeesalaries)
#Printing out the names of employees with salaries within 5k of the average
print("Name\t||\tSalary", end='\n\n')
for i in range(len(emp_sal)):
if emp_s
al[i]>= avg_sal-5 and emp_sal[i]<=avg_sal+5:
print(f'{emp_name[i]} \t||\t {emp_sal[i]}')
For safety reasons we do not allow file attachments.
#Lists storing the employee names and salaries
listofemployeenames = []
listofemployeesalaries = []
#Taking employee names
emp_name= input("What is the employee's name?")
listofemployeenames.append(emp_name)
#Taking employee salaries
emp_sal = float(input("What is the employee's salary?"))
listofemployeesalaries.append(emp_sal)
#Finding the average of all the salaries
avg_sal = sum(listofemployeesalaries)/len(listofemployeesalaries)
#Printing out the names of employees with salaries within 5k of the average
print("Name\t||\tSalary", end='\n\n')
for i in range(len(emp_sal)):
if emp_sal[i]>= avg_sal-5 and emp_sal[i]<=avg_sal+5:
print(f'{emp_name[i]} \t||\t {emp_sal[i]}')
In the last part you aren't using the list
len(emp_sal) should be len(listofemployeesalaries)
And then your if statement should use the list as well
#Lists storing the employee names and salaries
listofemployeenames = []
listofemployeesalaries = []
#Taking employee names
emp_name= input("What is the employee's name?")
listofemployeenames.append(emp_name)
#Taking employee salaries
emp_sal = float(input("What is the employee's salary?"))
listofemployeesalaries.append(emp_sal)
#Finding the average of all the salaries
avg_sal = sum(listofemployeesalaries)/len(listofemployeesalaries)
#Printing out the names of employees with salaries within 5k of the average
print("Name\t||\tSalary", end='\n\n')
for i in range(len(listofemployeesalaries)):
if listofemployeesalaries[i]>= avg_sal-5 and emp_sal[i]<=avg_sal+5:
print(f'{emp_name[i]} \t||\t {emp_sal[i]}')
You still have emp_sal[i]
#Lists storing the employee names and salaries
listofemployeenames = []
listofemployeesalaries = []
#Taking employee names
emp_name= input("What is the employee's name?")
listofemployeenames.append(emp_name)
#Taking employee salaries
emp_sal = float(input("What is the employee's salary?"))
listofemployeesalaries.append(emp_sal)
#Finding the average of all the salaries
avg_sal = sum(listofemployeesalaries)/len(listofemployeesalaries)
#Printing out the names of employees with salaries within 5k of the average
print("Name\t||\tSalary", end='\n\n')
for i in range(len(listofemployeesalaries)):
if listofemployeesalaries[i]>= avg_sal-5 and listofemployeesalaries[i]<=avg_sal+5:
print(f'{emp_name[i]} \t||\t {emp_sal[i]}')