Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7757273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:02:57+00:00 2026-06-01T13:02:57+00:00

I just wrote a program to calculate employee’s pay rates. To me, the program

  • 0

I just wrote a program to calculate employee’s pay rates. To me, the program looks just fine, but when I try to run it I get a restart, and it doesn’t run. I’ve tried restarting the Python GUI, but no luck. Here is the program:

def get_info():
    hours = int(input("How many hours did you work this week?", ))
    while hours < 8 or hours > 86:
        print('Error ---- you must work at least 8 hours and no more than 86 hours')
        hours = int(input('Please enter your hours worked again:', ))
    print()
    rate = float(input("Please enter your pay rate: $", ))
    while rate < 7.00 or rate > 50.00:
        print("Error ---- pay rate cannot be less than $7.00 or greater than $50.00")
        rate = float(input("Please re-enter your pay rate: $", ))

    return hours, rate

def calc_hours(num):
    if num < 40:
        reg_hours = num
        overtime = 0
    else:
        reg_hours = 40
        overtime = num - 40

    return reg_hours, overtime

def calc_pay(num1, num2, pay_rate):
    regular_pay = num1 * pay_rate
    overtime_pay = num2 * (pay_rate * 1.5)
    total_pay = regular_pay + overtime_pay

    return regular_pay, overtime_pay, total_pay

def main():
    get_info()
    calc_hours(hours)
    cal_pay(reg_hours, overtime, rate)

    print ()
    print ("                     Payroll Information")
    print ()
    print ("Pay Rate", format(rate, '14.2f'))
    print ("Regular Hours", format(reg_hours, '10.2f'))
    print ("Overtime Hours", format(overtime, '10.2f'))
    print ("Regular Pay", format(regular_pay, '10.2f'))
    print ("Overtime Pay", format(overtime_pay, '10.2f'))
    print ("Total Pay", format(total_pay, '10.2f'))

Yes, the chart is gonna be wonky. I haven’t been able to run it successfully so that it’ll come out smoothly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:02:59+00:00Added an answer on June 1, 2026 at 1:02 pm
    hours, rate = get_info()
    reg_hours, overtime = calc_hours(hours)
    regular_pay, overtime_pay, total_pay = calc_pay(reg_hours, overtime, rate)
    
    print ()
    print ("                     Payroll Information")
    print ()
    print ("Pay Rate", format(rate, '14.2f'))
    print ("Regular Hours", format(reg_hours, '10.2f'))
    print ("Overtime Hours", format(overtime, '10.2f'))
    print ("Regular Pay", format(regular_pay, '10.2f'))
    print ("Overtime Pay", format(overtime_pay, '10.2f'))
    print ("Total Pay", format(total_pay, '10.2f'))
    

    First, take a look at your main():. You called your get_info() function, when the function finish, it return hours, rate, but you did not do store the result. (which is your hours, rate) again, and so do the next two lines. When you call your methods, it return the answers, you have to store them to a variable.

    These are the 3 lines of changes

    hours, rate = get_info()
    reg_hours, overtime = calc_hours(hours)
    regular_pay, overtime_pay, total_pay = calc_pay(reg_hours, overtime, rate)
    

    Lastly, there is a typo calc_pay instead of cal_pay of what you write. So fixing that will make your program work, here is the output.

    Output

    How many hours did you work this week?8
    
    Please enter your pay rate: $20
    
                         Payroll Information
    
    Pay Rate          20.00
    Regular Hours       8.00
    Overtime Hours       0.00
    Regular Pay     160.00
    Overtime Pay       0.00
    Total Pay     160.00
    

    And let me explain to you what these assignment statement did. The form is like this:
    variable = expression

    1. The expression on the RHS is being evaluated (The value is a memory address)
    2. Storing the memory address in the variable on the LHS

    A link you might found helpful to read: Defining Functions

    In case you want to fix your chat, here is how to do it.

    pattern = '{0:15s}    {1:4.2f}'
    print(pattern.format('Pay Rate', rate))
    print(pattern.format('Regular Hours', reg_hours))
    print(pattern.format('Overtime Hours', overtime))
    print(pattern.format('Regular Pay', regular_pay))
    print(pattern.format('Overtime Pay', overtime_pay))
    print(pattern.format('Total Pay', total_pay))
    

    Output:

    Pay Rate           20.00
    Regular Hours      20.00
    Overtime Hours     0.00
    Regular Pay        400.00
    Overtime Pay       0.00
    Total Pay          400.00
    

    Explanation:

    pattern = '{0:15s}    {1:4.2f}'
    # 0 mean the blank should be filled with the first argument, 
    # the colon(:) specifies the formatting of the string / number.
    # s means to format a string, 15s means the string will be padded with spaces
    # so it will take up exactly 15 spaces, without the number, s just mean
    # use the string without any space padding
    # d means format an integer, 4d mean the integer will be padded with space
    # so it takes up exactly 4 spaces. f means float, and .2 mean 2 decimal point.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote program to convert decimal to binary for practice purposes but i get
I wrote a program to solve a complicated problem. This program is just a
I just started learning C, and wrote my hello world program: #include <stdio.h> main()
I just started learning C, and wrote my hello world program: #include <stdio.h> main()
I just wrote a stored function to calculate the working days between two dates.
I just wrote my first OpenMP program that parallelizes a simple for loop. I
When i run the code as is my output is: This program will calculate
I am new to Java Multithreading World, I wrote this program, I just wanted
I just wrote my first Python program and it works! It is a program
I just wrote a program that tokenizes a char array using pointers. The program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.