#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)

gentle geode
#
#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]}')
stray sage
#

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

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

lucid duneBOT
#

@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]}')



gentle geode
#
#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]}')
stray sage
#

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

gentle geode
#
#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]}')
stray sage
#

You still have emp_sal[i]

gentle geode
#
#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]}')
rugged obsidian
#

{emp_sal[i]}

#

Last line