DEV Community

Cover image for Pay Calculator
Scott Gordon
Scott Gordon

Posted on

1

Pay Calculator

# pay_calc.py
#   This program takes input of hours worked and hourly rate and calculates
#   the total wages for the week.
# by: Scott Gordon

def main():
    print("***** Welcome to the Pay Calculator *****\n")
    hours_worked = float(input("Enter the amount of hours worked: "))
    hourly_rate = float(input("Enter the hourly rate: "))

    def pay_calculator(hours, pay_rate):
        """Calculates total pay based on the amount of hours worked and pay 
        rate. Time-and-a-half is calculated for any hours worked over 40."""
        if (hours > 0) and (pay_rate > 0):
            if hours <= 40:
                pay = hours * pay_rate
                return f"\nYour pay is ${pay:.2f}"
            else:
                pay = (40 * pay_rate) + ((pay_rate * 1.5) * (hours - 40))
                return f"\nYour pay with overtime is ${pay:.2f}"
        else:
            return "\nYou must enter a number greater than 0 for hours and pay."
    print(pay_calculator(hours_worked, hourly_rate))


if __name__ == '__main__':
    main()

Enter fullscreen mode Exit fullscreen mode

Photo by Sharon McCutcheon on Unsplash

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay