Question & Answer: The program must have at least one input and at least one output. All user input must be validated. Th…..

The program must have at least one input and at least one output. All user input must be validated. This means the user is not allowed to just enter any value. You must check the value, and ask the user to enter it again, and repeat this loop until the user enters a valid value. Your program must use at least two arrays in meaningful ways. These two arrays can contain any type of values, as long as they are both used meaningfully in your program. Your program must have at least one loop that accesses the data in the arrays. For example, you might have an input loop that asks the user to enter the data one element at a time (be sure to validate the data). Or, you might have an output loop that writes the data to the console. Or, you might have a calculation loop that calculates one or more values, such as minimum value, maximum value, averages, and so on. You can have all three of those types of loops, if you want (the Lab 5 walkthrough video shows an example of each). Your program should be organized into separate modules. Each module should be “cohesive” and should only do one thing. Use parameters and arguments to pass values into your modules (don’t use global variables). The Python code should run correctly, and the logic should match your pseudocode. I JUST NEED A SIMPLE ONE

Expert Answer

 

Python Code:

def avgSalary(EmpWages):
“”” Function that finds average salary “””
# Initially set total to 0
total = 0;

# Iterating over array
for i in range(0, len(EmpWages)):
# Accumulating value
total += EmpWages[i];

# Finding and returning average
return (total / float(len(EmpWages)));

def printData(EmpNames, EmpWages):
“”” Function that prints Employee Names and wages to console “””
# Printing header
print(“nn %-20s %-20s n” %(“Employee Name”, “Employee Salary”));
# Iterating over arrays
for i in range(0, len(EmpNames)):
# Printing value
print(“n %-20s %-20.2f ” %(EmpNames[i], EmpWages[i]));

# Printing average salary
print(“nn Average Salary: %.2f nn” %(avgSalary(EmpWages)));

def readData(EmpNames, EmpWages):
“”” Function that reads data from user and stores in corresponding arrays “””

# Reading five employee’s details
for i in range(1, 6):
# Reading employee name
name = input(“n Enter Employee Name: “);

# Iterate till user enters a valid salary
while True:
try:
# Reading employee wage
wage = float(input(“n Enter Employee Salary: “));
break;
except:
print(“n Invalid Value!!! n”);

# Adding to arrays
EmpNames.append(name);
EmpWages.append(wage);

def main():
“””
Python program that reads employee names and finds the average salary
“””
# List that holds names
EmpNames = [];

# List that holds wages
EmpWages = [];

# Reading names and wages from user
readData(EmpNames, EmpWages);

# Printing report
printData(EmpNames, EmpWages);

# Calling main function
main();

___________________________________________________________________________________________

Code Screenshot:

Sample Run:

Still stressed from student homework?
Get quality assistance from academic writers!