This code when ran asks for job code and then hours worked, but when I put in 20 or 40 hours I get an error... indexerror: Tuple index out of range Its supposed to be for up to 40 hours, no more then that.. how do I fix the tuple range? # Name: Erica Strong # Prog Purpose: This program computes employee weekly pay # Category codes: # C Cashier: $16.50 # S Stocker: $15.75 # J Janitor: $15.75 # M Maintenance: $19.50 import datetime # define pay rates & deduction rates PAY_RATES = (16.50, 15.75, 15.75, 19.50) DEDUCTION_RATES = (0.12, 0.03, 0.062, 0.0145) # define global variables inout = 'C' # C means Cashier, S means Stocker, J means Janitor, M means Maintenance hoursworked= 0 payrates = 0 deductionrates = 0 grosspay = 0 netpay = 0 ############ Define program functions ############ def main(): another_employee = True while another_employee: hours_worked, job_code = get_user_data() gross_pay = perform_calculations(hours_worked, job_code) total_deductions, deductions = perform_deductions(gross_pay) net_pay = gross_pay - total_deductions display_results(hours_worked, gross_pay, deductions, total_deductions, net_pay) yesno = input("\nWould you like to enter data for another employee? (Y/N):") if yesno.upper() != "Y": another_employee = False   def get_user_data(): while True: job_code = input("Please enter your job category (C=Cashier, S=Stocker, J=Janitor, M=Maintenance):") if job_code.upper() in ['C', 'S', 'J', 'M']: break print('Invalid job code. Please enter a valid job code.') hours_worked = float(input("Please enter your hours for the week: ")) pay_rate_index = ord(job_code.upper()) - ord('C') return hours_worked, pay_rate_index def perform_calculations(hours_worked, pay_rate_index): gross_pay = hours_worked * PAY_RATES[pay_rate_index] return gross_pay def perform_deductions(gross_pay): deductions = [] for rate in DEDUCTION_RATES: deduction_amount = gross_pay * rate deductions.append(deduction_amount) total_deductions = sum(deductions) return total_deductions, deductions def display_results(hours_worked, gross_pay, deductions, total_deductions, net_pay): print('\nFresh Food Marketplace') print(f'\nHours worked: {hours_worked}') print(f'\nGross pay: ${gross_pay:.2f}') for i, deduction in enumerate(deductions): print(f'Deduction {i+1}: ${deduction:.2f}') print(f"Total deductions: ${total_deductions:.2f}") print(f"Net pay: ${net_pay:.2f}") print(str(datetime.datetime.now())) ############ call on main program to execute ############ main()   (please type answer not write by hend)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This code when ran asks for job code and then hours worked, but when I put in 20 or 40 hours I get an error... indexerror: Tuple index out of range Its supposed to be for up to 40 hours, no more then that.. how do I fix the tuple range?

# Name: Erica Strong

# Prog Purpose: This program computes employee weekly pay

# Category codes:

# C Cashier: $16.50

# S Stocker: $15.75

# J Janitor: $15.75

# M Maintenance: $19.50

import datetime

# define pay rates & deduction rates

PAY_RATES = (16.50, 15.75, 15.75, 19.50)

DEDUCTION_RATES = (0.12, 0.03, 0.062, 0.0145)

# define global variables

inout = 'C' # C means Cashier, S means Stocker, J means Janitor, M means Maintenance

hoursworked= 0

payrates = 0

deductionrates = 0

grosspay = 0

netpay = 0

############ Define program functions ############

def main():

another_employee = True

while another_employee:

hours_worked, job_code = get_user_data()

gross_pay = perform_calculations(hours_worked, job_code)

total_deductions, deductions = perform_deductions(gross_pay)

net_pay = gross_pay - total_deductions

display_results(hours_worked, gross_pay, deductions, total_deductions, net_pay)

yesno = input("\nWould you like to enter data for another employee? (Y/N):")

if yesno.upper() != "Y":

another_employee = False

 

def get_user_data():

while True:

job_code = input("Please enter your job category (C=Cashier, S=Stocker, J=Janitor, M=Maintenance):")

if job_code.upper() in ['C', 'S', 'J', 'M']:
break

print('Invalid job code. Please enter a valid job code.')

hours_worked = float(input("Please enter your hours for the week: "))

pay_rate_index = ord(job_code.upper()) - ord('C')

return hours_worked, pay_rate_index

def perform_calculations(hours_worked, pay_rate_index):

gross_pay = hours_worked * PAY_RATES[pay_rate_index]

return gross_pay

def perform_deductions(gross_pay):

deductions = []

for rate in DEDUCTION_RATES:

deduction_amount = gross_pay * rate

deductions.append(deduction_amount)

total_deductions = sum(deductions)

return total_deductions, deductions

def display_results(hours_worked, gross_pay, deductions, total_deductions, net_pay):

print('\nFresh Food Marketplace')

print(f'\nHours worked: {hours_worked}')

print(f'\nGross pay: ${gross_pay:.2f}')

for i, deduction in enumerate(deductions):

print(f'Deduction {i+1}: ${deduction:.2f}')

print(f"Total deductions: ${total_deductions:.2f}")

print(f"Net pay: ${net_pay:.2f}")

print(str(datetime.datetime.now()))

############ call on main program to execute ############

main()

 

(please type answer not write by hend)

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education