Please note: *formatting is very important* Working with Variables, Functions, &
ID: 3752799 • Letter: P
Question
Please note: *formatting is very important*
Working with Variables, Functions, & Strings
Financial application: Payroll & Access Code creation
VCU Widgets is new startup company in Richmond and has learned that you are taking a programming class. They are very interested in creating a payroll and Access Code program and they have come to you for help. You will create a Python program (named: LastnameFirstInitial_PA2) to calculate the total net paycheck and Access Code using the following information.
Data to be input:
Employee Name (first & last)
Number of hours worked
Hourly pay rate
Married or Single (to determine Federal tax rate)*
State tax rate
*Married tax rate 8%, Single tax rate 12% (use decision statement to test first letter only, make sure to change the capitalization to what you are testing). You may also want to use the Round function.
Output:
Use hourly wage and hours worked to determine Gross Pay. Then use appropriate withholding percentages to determine deductions.
Determine Access Code:
Create and combine the following 3 strings to determine Access Code. You will use string functions, methods, and operators for this.
String 1.Use remainder division to divide the length of the name string by 3. Use the portion of the name that starts at that position number, and includes up to the character in position 5 (see 2 examples below)
String 2.Use the last 4 letters, in upper case
String 3.Use the min and max letters/characters
Sample input and output: Enter employee's name (first and last): Dolly Madison Enter number of hours worked this week: 34 Enter hourly pay rate: 12.85 Please enter single or Married: s Enter state tax withholding rate: .05 Employee Name: Dolly Madison Hours Worked: 34 Pay Rate: $12.85 Gross Pay: $436.90 Deductions: Federal withholding (12%): $52.43 State withholding (58): $21.84 Total Deduction:$74.27 Dolly Madison net pay check: $362.63 Your new access code is: olly ISON y Enter employee's name (first and last) Samuel Duke Enter number of hours worked this week: 11 Enter hourly pay rate: 27.5 Please enter Single or Married: Married Enter state tax withholding rate: .5 Employee Name: Samuel Duke Hours Worked: 11 Pay Rate: $27.50 Gross Pay: $302.50 Deductions: Federal withholding (88): $24.20 state withholding (50%): $151.25 Total Deduction: $175.45 Samuel Duke net pay check: $127.05 Your new access code is: muelDUKE uExplanation / Answer
ScreenShot
-----------------------------------------------------
program
#User prompt(Inputs)
name=input("Enter employee's name(first and last): ")
work_hrs=int(input("Enter the number of hours worked this week: "))
pay_rate=float(input("Enter hourly pay rate: "))
married_status=(input("Please enter Single or Married(S or M): "))
married_status=married_status[0].upper();
withhold_rate=float(input("Enter state tax withholding rate: "))
#Output display and calculations
print(" Employee Name: %s "%name)
print("Hours Worked: %d"%work_hrs)
print("Pay Rate: $%#.2f"%pay_rate)
#Gross pay calculation
gross_pay=work_hrs*pay_rate
print("Gross Pay: $",round(gross_pay,2))
print("Deductions:")
#if married status is single
if(married_status=='S'):
#calculate federal holdings and display
federal_withhold=gross_pay*.12
print(" Federal Withholding (12%): $",round(federal_withhold,2))
#calculate state holdings and display
state_withhold=gross_pay*withhold_rate
print(" State Withholding (",(withhold_rate*100),"%): $",round(state_withhold,2))
#calculate total deduction and display
total_deduction=federal_withhold+state_withhold
print(" Total Deduction: $",round(total_deduction,2))
#calculate net pay and display
net_pay=gross_pay-total_deduction
print(name," net pay check: $",round(net_pay,2))
#Generate access code and display
name_split=name.split()
fname=name_split[0]
length=len(name_split[0])
round_length=round(length/3)
string1=""
for i in range(round_length,length+1):
string1=string1+fname[i-1]
string2=name[-4:].upper()
string1=string1+" "+string2+" "+max(name)
print("Your new access code is: ",string1)
#If status is married
elif(married_status=='M'):
#calculate federal holdings and display
federal_withhold=gross_pay*.08
print(" Federal Withholding (8%): $",round(federal_withhold,2))
#calculate state holdings and display
state_withhold=gross_pay*withhold_rate
print(" State Withholding (",(withhold_rate*100),"%): $",round(state_withhold,2))
#calculate total deduction and display
total_deduction=federal_withhold+state_withhold
print(" Total Deduction: $",round(total_deduction,2))
#calculate gross pay and display
net_pay=gross_pay-total_deduction
print(name," net pay check: $",round(net_pay,2))
#Generate access code and display
name_split=name.split()
fname=name_split[0]
length=len(fname)
round_length=round(length/3)
string1=""
for i in range(round_length,length+1):
string1=string1+fname[i-1]
string2=name[-4:].upper()
string1=string1+" "+string2+" "+max(name)
print("Your new access code is: ",string1)
------------------------------------------------------------------------
Output
Enter employee's name(first and last): Dolly Madison
Enter the number of hours worked this week: 34
Enter hourly pay rate: 12.85
Please enter Single or Married(S or M): s
Enter state tax withholding rate: 0.05
Employee Name: Dolly Madison
Hours Worked: 34
Pay Rate: $12.85
Gross Pay: $ 436.9
Deductions:
Federal Withholding (12%): $ 52.43
State Withholding ( 5.0 %): $ 21.84
Total Deduction: $ 74.27
Dolly Madison net pay check: $ 362.63
Your new access code is: olly ISON y
Press any key to continue . . .
----------------------------------------------
Note
I am using python 3.6