1

I'm working on my first non-revisable (after being turned in) task for my programming class.

In this task, I take a list of employees' names, level (for commission), hours worked, and sales generated.

I then output what the combined sales and commission and hourly pay (plus OT), as well as each individual salesperson's name followed by their own commission and wage total (including OT)

I have already made two functions for determining commission rate and hourly rates.

I should mention that we haven't covered dictionary use yet. In doing some reading I've seen that usually when multiple lists and I think nested lists are involved, dictionaries are advisable. Since we haven't covered that, Idk if I should use them. I believe my instructor wants us to only use that which we've been taught. This wasn't explicitly stated though.

EDITED How do I keep the "for x in range(num_employees) from being counted if incorrect level is supplied?

num_employees = int(input("Enter number of salespersons to be evaluated: "))
employee_records = []
wage = None
lrange = [1, 2, 3, 4]
for x in range(num_employees):
    record = []
    name = (input("Enter employee name: "))
    try:
        level = int(input("Enter this employee's level: "))
    except ValueError:
        print("Employee level must be from 1 to 4.")
        num_employees += 1
        continue
    try:
        hours = float(input("Enter hours worked by this employee: "))
    except ValueError:
        print("Entry must be a number.")
        num_employees += 1
        continue
    try:
        sales = float(input("Enter revenue generated by this employee: "))
    except ValueError:
        print("Entry must be a number.")
        num_employees += 1
        continue

    record.append(name)
    record.append(level)
    record.append(hours)
    record.append(sales)
    employee_records.append(record)

print(employee_records)
Grelm
  • 55
  • 1
  • 7
  • 1
    Re, "I believe my instructor wants us to only use that which we've been taught." That is almost always a safe bet. Maybe you can get extra credit if you do it _both_ the instructor's way (shows that you were paying attention in lecture), _and_ the cool way. – Solomon Slow Oct 30 '21 at 01:20
  • 1
    There are a few issues with this line: `int(input("Enter this employee's level: ") != 1 or 2 or 3 or 4)`. I suggest you try to break this out into multiple lines and check each line to see if it is giving you want you want. Once you have what you want, append that to your list. – ramzeek Oct 30 '21 at 01:22
  • 1
    `list.append` always returns `None`. This is common with python functions. If you change a mutable object, don't also return something. But its more of a guideline than a rule. Builtin functions and methods follow this rule, but every module is free to do what it wishes. Generally, when something isn't working, put in a `print` like maybe `print(level_list.append(int(input("Enter this employee's level: ") != 1 or 2 or 3 or 4)))`. – tdelaney Oct 30 '21 at 01:22
  • 1
    Also, consider a list of `[employee, level, hours, sales]` to hold a record of one employee's information. Prompt for all 4 values and add them to this list. Now, put that list into an outer list of all the records. – tdelaney Oct 30 '21 at 01:25
  • @tdelaney I definitely like that idea. How would I go about creating new lists depending on what the number of employees entered is? Like if there are 5 employees to be evaluated, I'd need 5 lists – Grelm Oct 30 '21 at 01:27
  • 2
    Alos, `!= 1 or 2 or 3 or 4` doesn't do what you want. Do a bit of research on how to do boolean operations or how to use the `in` operator. – tdelaney Oct 30 '21 at 01:27
  • 1
    Right. So, you create the outer list `employee_records = []`. Then prompt for the number of employees. Now a loop `for index in range(number_of_employees):` and in that block, keep creating new sublists. `record = []`. Then get employee name and appned to that list. Then level, hours, sales, appending each to `record`. When you are done, `employee_records.append(record)`. Then the loop will repeat and it will go back to prompt for the next one. – tdelaney Oct 30 '21 at 01:30
  • Good point about the count. To deal with that, use a `while` loop instead of a `for`. `while len(employee_records) < num_employees;` Now, the `while` will keep going until you've appended all you want. – tdelaney Oct 30 '21 at 02:18

0 Answers0