Zack Allen
Zack Allen

Reputation: 27

How to make a variable after a certain integer in python

Im brand new to programing this is literally my second day just looking at this stuff. So please forgive me if this is answered somewhere already or if its a really dumb question, this is still like witch craft to me.

Anyways I have to make a pay calculator and I want to make a variable for anything after 40 to be overtime. This is what I have so far.

input("Enter Name, Or 0 To Quit: ")
hour = float(input("Hours: "))
if hour > 40:

    overTime = float(print("Over Time Hours: "))
    payRate = float(input("Pay Rate: $ "))

    overTime = overTimeHour * 1.5
    grossPay = hour * payRate + overTime

    print("\nGross Pay: $", (grossPay))
else:
    payRate = float(input("Pay Rate: $ "))

    grossPay = hour * payRate

    print("\nGross Pay: $",(grossPay))

Upvotes: 0

Views: 37

Answers (1)

Phil
Phil

Reputation: 1674

I don't think you want your overTime variable to be a float(print()). That'll probably throw an error. You already have the total number of hours, so isn't the number of overtime hours just hours - 40? I don't think you need another input for that. Then, you need to change up your formula for gross pay a bit.

I also moved the input for payRate out, since it applies to both conditions in the if statement.

The following code should do the trick:

input("Enter Name, Or 0 To Quit: ")
hour = float(input("Hours: "))
payRate = float(input("Pay Rate: $ "))
if hour > 40:

    overTimeHours = hour - 40

    # This can be simplified (via commutative property) if you'd like
    grossPay = (40 * payRate) + (overTimeHours * 1.5 * payRate)

    print("\nGross Pay: $", (grossPay))
else:
    grossPay = hour * payRate

    print("\nGross Pay: $",(grossPay))

Upvotes: 1

Related Questions