Q:

How to select a range of numbers to multiply an hourly wage by

Im reading in a file with employee information on it. First name, last name, hours worked, hourly wage. I need to calculate regular pay, so hourly wage * hours between and including 0 and 40. Also, time and a half which is between 41 and 45, inclusive. My question is how do I only use the hours between 0 and 40 to get the regular pay? This is my current code: 
def main():
print()
print("This program will compute payroll.")
print("Written by Josh Sollenberger.")
print()

filename = input("Please enter the emplyee file name: ")
infile = open(filename, 'r')
print()
for line in infile:
    first,last,hours,wage = line.split(',')
    while int(hours) >= 0 and int(hours) <= 40:
        regPay = float(wage)*hours
    print(first,last,hours,wage,regPay)

main()
This is telling me i'm referencing regPay before assignment. 

A:

I've done this before, using min and max
regPay = float(wage) * min(int(hours),40)
# min(hours,40) will return hours, unless hours > 40 then it will return 40
OTpay = float(wage) * OVERTIMERATE * max(int(hours)-40,0)
# max(hours-40,0) will return hours-40, unless hours <= 40 then it will return 0

The reason it's telling you that you're referencing regPay before assignment is because you're ONLY getting to that regPay = float(wage)*hours line (that assigns regPay) when int(hours) is between 0 and 40. If it's >= 41, it never gets in there!
The incredibly long don't ever do this version of this code would be:
OVERTIMERATE = 1.5 # maybe 2?
first,last,hours,wage = line.split(',')
hours, wage = int(hours), float(wage) # Decimal is better here, but...
OTpay, regPay = 0,0 # initialize
while hours > 40:
    hours -= 1
    OTpay += wage*OVERTIMERATE
while hours > 0:
    hours -= 1
    regPay += wage

EDIT PER COMMENTS
reg_hours = min(int(hours), 40)
timeandhalf_hours = min(max(int(hours)-reg_hours),0),5)
doubletime_hours = max(int(hours) - (reg_hours + timeandhalf_hours), 0)

regPay = float(wage) * reg_hours
timeandhalfPay = float(wage) * 1.5 * timeandhalf_hours
doubletime_hours = float(wage) * 2 * doubletime_hours

Again the long form:
total_pay = 0
hours = int(hours)
wage = float(wage)

for i in range(1,hours+1):
    if i <= 40:
        total_pay += wage
    elif i <= 45:
        total_pay += wage * 1.5
    else:
        total_pay += wage * 2

