Good evening,
I am new to this website. And I am also new to Python. Actually I am currently in a Python class at school. I am having some difficulty with this Payroll Program. I was wondering if anyone could help. Here is my code:

def hours():
hours = input("How many hours did they work?: ")
return hours

def payrate():
payrate = input("How much is their payrate?: ")
return payrate

def calchours(pr, h):
if h > 40:
rh = 40
oh = h - 40
if h > 60:
print "Can't exceed 60 hours in a week!"
if h <= 0:
print "Can't work less than 1 hour a week!"
else:
rh = h
oh = 0

def main():
hrs = hours()
pyr = payrate()
calchours (pyr, hrs)

main()

What I am looking for is trying to get the message that pops up if someone works less than 1 hour a week. I have the greater than 60 hours working, but I can't get the less than 1 hour working. This is just the start of the program. I also am trying to get this to loop until anyone types DONE. Any help would be grateful.

(P.S. I would like to thank Vegaseat for his prior code).

(P.S.S. I know I have the tabbing correct. I just don't know how to paste it like actual code).

PLEASE use code tags; re-edit your above post. As you can see, your indentation gets lost without them, and it's essential for Python.

Shouldn't

if h <= 0:
    print "Can't work less than 1 hour a week!"

be changed to

if h < 1:
    print "Can't work less than 1 hour a week!"

Tell me if that changes your error message for less than 1 hour a week.

Good evening,
I am new to this website. And I am also new to Python. Actually I am currently in a Python class at school. I am having some difficulty with this Payroll Program. I was wondering if anyone could help. Here is my code:

def hours():
    hours = input("How many hours did they work?: ")
    return hours
 
def payrate():
    payrate = input("How much is their payrate?: ")
    return payrate
 
def calchours(pr, h):
    if h > 40:
        rh = 40
        oh = h - 40
        if h > 60:
            print "Can't exceed 60 hours in a week!"
            if h <= 0:
                print "Can't work less than 1 hour a week!"
    else:
        rh = h
        oh = 0
    
def main():
    hrs = hours()
    pyr = payrate()
    calchours (pyr, hrs)
 
main()

What I am looking for is trying to get the message that pops up if someone works less than 1 hour a week. I have the greater than 60 hours working, but I can't get the less than 1 hour working. This is just the start of the program. I also am trying to get this to loop until anyone types DONE. Any help would be grateful.

(P.S. I would like to thank Vegaseat for his prior code).

(P.S.S. I know I have the tabbing correct. I just don't know how to paste it like actual code).

Well I hoped that worked. I very new to this website. But the information I have found on this website has been helpful.

This is the kind of this that makes for an angry employee on pay day:

print "Can't exceed 60 hours in a week!"

Yes, I know it's probably part of your instructions.

You've already determined that h > 40 , so you know this will never be true:

if h <= 0:
    print "Can't work less than 1 hour a week!"

Also, you're testing for the wrong condition if you are checking for less than 1 hour worked.

Shouldn't

if h <= 0:
    print "Can't work less than 1 hour a week!"

be changed to

if h < 1:
    print "Can't work less than 1 hour a week!"

That wont change anything because h<=0 will be true if h is 0 or below, the same will be for h<1. That is though, if we are only working with integers. So if the user enters a float or the program is working with floats then you would be correct shadwickman.

My assignment involves me to check for both parameters that are if the employee has worked no more then 60 hours in a week and less then 1 hour. Those are both the parameters I need to meet. So in order for it to check if then would work less then 1 I would need to set up a float?

Well only if you expect the employee to work for lets say 14.5 hours, then you would have to use

if h<1:
    print "error"

But if you are only dealing with whole numbers then you can stick with what you have got

if h <=0:
    print "error"

Does that make sense?

Depending on the version of Python you are using, this may or may not return a string
hours = input("How many hours did they work?: ")
If it is a string and not a float
print type(hours),
the function should
return float(hours)
Hopefully, it is obvious why you want to do this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.