{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf830 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \margl1440\margr1440\vieww28600\viewh18000\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 \f0\fs24 \cf0 #!/usr/bin/env python3\ # -*- coding: utf-8 -*-\ """\ Last edited on Tue Oct 10 15:28 2017\ \ @author: randallhall\ """\ \ # program using Python3 to prompt the user for their name, hourly wage, and \ # the hours they worked each day for a pay period and calculates the user's \ # take home pay!\ \ DoW = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', \ 'Saturday']\ # Introduction\ name = input("Time to begin calculating your net pay! May I have your name " \ "please? ")\ \ print ("Ah! So your name is \{\} and you want to calculate your net pay. " \ "Please follow the following prompts".format(name))\ \ while True: \ try:\ wage = float(input("May I have your hourly wage please? "))\ break\ \ except:\ print("Please type in a number!")\ \ while True: \ try:\ retper = float(input("What percent are you contributing to your 401(k)? "))\ if 0 <= retper <= 100:\ retper = retper\ break\ else:\ print('Sorry. Value must be between 0 and 100')\ except ValueError:\ print("Please type in a number!")\ \ # STEP 1: Prompt for how many hours worked on each day of the week\ # Begin week 1 prompting\ W1L = [] #W1L is list which holds all hours worked each day\ print("Enter hours of week 1")\ for i in range(7):\ while True:\ try:\ day = float(input("How many hours did you work \{\}? ".format(DoW[i])))\ if 0 <= day <= 24: \ W1L.append(day)\ break\ else:\ print('Sorry. Value must be between 0 and 24.')\ except ValueError: \ print("Input is not valid. How many hours did you work \{\}? ".format(DoW[i]))\ \ W1HT = sum(W1L) #W1HT = Week 1 Hourly Total\ print ("Your total hours for week 1 of this pay period is \{\} hours"\ .format(W1HT))\ \ # Begin week 2 prompting:\ W2L = [] # W2L is a list which holds all hours worked each day\ print("Enter hours of week 2")\ \ for i in range(7):\ while True:\ try:\ day = float(input("How many hours did you work \{\}? ".format(DoW[i])))\ if 0 <= day <= 24: \ W2L.append(day)\ break\ else:\ print('Sorry. Value must be between 0 and 24.')\ except ValueError: \ print("Input is not valid. How many hours did you work \{\}? ".format(DoW[i]))\ \ W2HT = sum(W2L) #W2HT = Week 2 Hourly Total\ print ("Your total hours for week 2 of this pay period is \{\} hours"\ .format(W2HT))\ \ # STEP 3: Calculate hours per week:\ if W1HT > 40:\ OTH1 = W1HT - 40\ W1SG = round((wage * 40) + (OTH1 * (wage*1.5)), 2)\ \ else:\ W1SG = round(W1HT * wage, 2)\ \ if W2HT > 40:\ OTH2 = W2HT - 40\ W2SG = round((wage * 40) + (OTH2 * (wage*1.5)), 2)\ \ else:\ W2SG = round(W2HT * wage, 2)\ \ PPHT = round(W1HT + W2HT, 2) #PPHT = Pay Period Hours Total\ TWSG = round(W1SG + W2SG, 2) #TWSG = Total Wage Salary Gross\ print ("\\n")\ print ("\{\}, your total hours for this pay period is \{\} hours"\ .format(name, PPHT))\ print ("\{\}, your gross wages for this pay period is $\{\}".format(name, TWSG))\ \ # Step 4: Calculate 401(k) contribution\ ret = round(float(retper/100) * TWSG, 2)\ print ("401k contribution is $\{\}".format(ret))\ AD = TWSG - ret\ # STEP 5: Calculate Fed Witholding.\ \ if 0 <= AD < 9325: # 0 <= AD < 9325\ HOL = round(AD * .10, 2)\ elif 9325 <= AD < 37950: # 9325 <= AD < 37950\ HOL = round(AD - (932.50 + ((AD - 9325)*(0.15 * AD))), 2)\ elif 37950 <= AD < 91900: # 37950 <= AD < 91900\ HOL = round(AD - (5226.25 + ((AD - 37950)*(0.25 * AD))), 2)\ elif 91900 <= AD < 191650: # 91900 <= AD < 191650\ HOL = round(AD - (18713.75 + ((AD - 91900)*(0.28 * AD))), 2)\ elif 191650 <= AD < 476700: # 191650 <= AD < 476700\ HOL = round(AD - (46643.75 + ((AD - 191650)*(0.33 * AD))), 2)\ elif 416700 <= AD < 418400: # 416700 <= AD < 418400\ HOL = round(AD - (120910.25 + ((AD - 416700)*(0.35 * AD))), 2)\ else:\ HOL = round(AD - (121505.25 + ((AD - 418400)*(0.396 * AD))), 2)\ print ("Federal income tax is $\{\}".format(HOL)) \ \ # STEP 6: Calculate Fed MED/EE\ MED = round(0.0145 * TWSG, 2)\ print ("Medicare tax is $\{\}".format(MED))\ \ # Step 7: Calculate Fed OASDI/EE\ OAS = round(0.062 * TWSG, 2)\ print ("Social Secuity tax is $\{\}".format(OAS))\ \ # Step 8: Calculate Net Pay\ WNP = round(AD - (HOL + MED + OAS),2)\ print ("\{\}, your net pay is $\{\}".format(name, WNP))}