Question

In: Computer Science

Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the...

Python - Rewriting a Program

Rewrite Program 1 using functions. The required functions are in the table below.

Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents.

The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as follows:

  • 0 – 1    Dependents:    Tax = 20%
  • 2 – 3    Dependents:    Tax = 15%
  • 4+        Dependents:    Tax = 10%

After calculating the net pay, print the name of the user, the monthly gross pay, the number of dependents, the gross pay, the tax rate, and the net pay.

The formula to compute the net pay is: monthly gross pay – (monthly pay * tax rate)


function

Description

read_name()

Reads the name entered, and returns the name.

read_gross_pay()

Reads the gross pay amount, and returns the amount.

read_dependents()

Reads the number of dependents, and returns the number.

compute_tax_rate(dependents)

Computes and returns the tax rate, based on the number of dependents.

compute_net_pay(gross_pay, rate)

Computes and returns the net pay, based on the gross pay and the tax rate.

main()

Main function of the program.

Sample run:

Enter your name: Ron Swanson
Enter your gross pay: $3500
Enter number of dependents: 0

Name:      Ron Swanson
Gross pay: $3500.00
Dependents: 0
Tax rate: 20%
Net Pay: $2800.00

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new python program with name "main.py" is created, which contains following code.

main.py :

#function to read name from the user
def read_name():
#asking user to enter your name
name=input("Enter your name: ")
return name;#return name

#function to read gross pay amount
def read_gross_pay():
#asking user to enter gross pay amount
grossPay=float(input("Enter your gross pay:$"))
return grossPay #return grossPay
  
#function to read number of dependents
def read_dependents():
#asking to enter number of dependents
dependents=int(input("Enter number of dependents: "))
return dependents #return

#function to Computes and returns the tax rate
def compute_tax_rate(dependents):
taxRate=0 #variable to store tax rate
#checking number of dependents
if(dependents>=0 and dependents<=1):
#if dependents is from 0 to 1 tax=20%
taxRate=0.20 #set taxRate
elif(dependents>=2 and dependents<=3):
#if dependents is from 2 to 3 tax=15%
taxRate=0.15 #set taxRate
elif(dependents>=4):
#if dependents is greater than or equal to 4, tax=10%
taxRate=0.10 #set taxRate
return taxRate #return tax rate

#function to Computes and returns the net pay
def compute_net_pay(gross_pay, rate):
#calculate and return net pay
return gross_pay-(gross_pay * rate)
  
#function main
def main():
name=read_name() #call function to read name
grossPay=read_gross_pay() #call function to read_gross_pay
dependents=read_dependents() #call function to read dependents
taxRate=compute_tax_rate(dependents) #call function to compute tax rate
netPay=compute_net_pay(grossPay,taxRate) #call function to compute net pay
print("Name :"+name) #print name
print("Gross Pay :$"+str(grossPay)) #print gross pay
print("Dependents:"+str(dependents)) #print dependents
print("Tax Rate :",(taxRate*100),"%") #print tax rate
print("Net Pay:$"+str((netPay))) #print net pay
#call to main
if __name__=="__main__":
main()

Screen for Indentation :

======================================================

Output : Compile and Run main.py to get the screen as shown below

Screen 1 :main.py

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Python 3 Fix this: The program is rewriting the product in excel everytime it gets executed...
Python 3 Fix this: The program is rewriting the product in excel everytime it gets executed i want to make a list and add new products everytime submit button its executed # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries...
This program is written by Ruby and Please rewrite this program as python. input_lines = gets.split("...
This program is written by Ruby and Please rewrite this program as python. input_lines = gets.split(" ") tasizan = input_lines[0].to_i hikizan = input_lines[1].to_i cnt=-0 drill=[] while cnt<tasizan kazu1 = rand(100) kazu2 = rand(100) next if kazu1+kazu2>99 next if drill.include?("#{kazu1} + #{kazu2} =") drill.push("#{kazu1} + #{kazu2} =") cnt+=1 end cnt=0 while cnt<hikizan kazu1 = rand(100) kazu2 = rand(100) next if kazu1 <= kazu2 next if drill.include?("#{kazu1} - #{kazu2} =") drill.push("#{kazu1} - #{kazu2} =") cnt+=1 end puts drill.sample(tasizan+hikizan)
Please paraphrase or rewrite me this text. please do not use paraphrasing or rewriting tool The...
Please paraphrase or rewrite me this text. please do not use paraphrasing or rewriting tool The effect of internal curing in the compressive strength depends on the specific mixture proportions, curing conditions and testing age. (Bentz et al., 2011 pp. 31) Use of the LWA will decrease the compressive strength of the concrete in the beginning of its age. That is expected because the specific gravity of the LWA is lower, therefore leading to lower strength compared to concrete with...
Do it in python please Write a program using functions and mainline logic which prompts the...
Do it in python please Write a program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a list. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a...
Write a Python program using functions and mainline logic which prompts the user to enter a...
Write a Python program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum, the numbers should...
Using python Write a program that has 3 functions, named write_to_file, read_from_file, and ask_user. The write_to_file...
Using python Write a program that has 3 functions, named write_to_file, read_from_file, and ask_user. The write_to_file function should have 2 parameters, file_name and data. When called, the function will open a file with the name stored in the file_name variable, write the information stored in data, then close the file. The read_from_file function will have 1 parameter, file_name. When called, the function will open a file with the name stored in the file_name variable, print the contents of the file,...
Write a Python program with correct indentation using functions and mainline logic which prompts the user...
Write a Python program with correct indentation using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a list. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum,...
Python 3 Rewrite KNN sample code using KNeighborsClassifier . ● Repeat KNN Step 1 – 5,...
Python 3 Rewrite KNN sample code using KNeighborsClassifier . ● Repeat KNN Step 1 – 5, for at least five times and calculate average accuracy to be your result. ● If you use the latest version of scikit -learn, you need to program with Python >= 3.5. ● Use the same dataset: “ iris.data ” ● Split your data: 67% for training and 33% for testing ● Draw a line chart: Use a “for loop” to change k from 1...
In this assignment, you are expected to rewrite the program from assignment7 using structs. That is,...
In this assignment, you are expected to rewrite the program from assignment7 using structs. That is, instead of using multiple arrays (one for each field, you need to create a single array of the datatype you should create as a struct). So, write a C++ program (use struct and dynamic memory allocation) that reads N customer records from a text file (customers.txt) such as each record has 4 fields (pieces of information) as shown below: Account Number (integer) Customer full...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT