Write a Python Program to Read The Salary For nc Employees

Assuming there are n number of employees in a company,  you have to read the salary of each employee and print it on the console.

 

 

Write a Python Program to Read The Salary For nc Employees



Write a Python Program to Read The Salary For nc Employees

Let's  take a variable  named  count  and ask a user to enter the number of employees.  Once we get the number of employees, let's take an empty list of integers.  is using the for loop lets ask users to enter the salary of each employee,  convert the salary to integer.

count = int(input("Enter Number of Employee : "))
salary = []
for index in range(count):
   temp = int(input(f"Enter Employee #{index+1} Salary : "))
   salary.append(temp)

 




Once we get the salary for each employee stored in the list.  use a for loop to iterate all the salaries of employees present in the list of  integers.   using the print statement print all the
salaries of employees.

print("The Employees Salary is ... ")
for index, pay in enumerate(salary):
   print(f"Employee #{index+1} earns {pay}")

 




Use a print statement to print the average of the salary by calculating the sum of salary / the count.  use the floating point formatting and print the average of the  salary

print("Average of Employee Salary is : %.2f" % (sum(salary)/ count))

 




Full program
=============

count = int(input("Enter Number of Employee : "))
salary = []
for index in range(count):
   temp = int(input(f"Enter Employee #{index+1} Salary : "))
   salary.append(temp)

print("The Employees Salary is ... ")
for index, pay in enumerate(salary):
   print(f"Employee #{index+1} earns {pay}")

print("Average of Employee Salary is : %.2f" % (sum(salary)/ count))





Output
==========

Enter Number of Employee : 3
Enter Employee #1 Salary : 15500
Enter Employee #2 Salary : 20000
Enter Employee #3 Salary : 18900

The Employees Salary is ...
Employee #1 earns 15500
Employee #2 earns 20000
Employee #3 earns 18900

Average of Employee Salary is : 18133.33


 

Conclusion
===========

Comment down below if you have any queries or suggestions.

 



Can you improve this Python program???

Post a Comment

0 Comments