Question

In: Computer Science

So previously in my class I had to write a python program where the user would...

So previously in my class I had to write a python program where the user would enter the price for 5 different items, and it would calculate the subtotal, total tax owed and the total amount owed. Now I need to write a program that would do the same but would be done using modules in the code, I am having a hard time figuring modules out. Below is the code from the original program not using modules:

# Enter price for Item1
item1 = float(input('Enter the price for item1: '))

# Enter price for Item2
item2 = float(input('Enter the price for item2: '))

# Enter price for Item3
item3 = float(input('Enter the price for item3: '))

# Enter price for Item4
item4 = float(input('Enter the price for item4: '))

# Enter price for Item5
item5 = float(input('Enter the price for item5: '))

print()

# Calculate the total owed before tax
subTotal = item1 + item2 + item3 + item4 + item5
print('The subtotal of the items is: ', subTotal)

# Calculate the total tax amount owed
totalTax = subTotal * .06
print('The total tax owed is: ', totalTax)

# Calculate the total amount owed
totalAmount = subTotal + totalTax
print('The total amount owed is: ', totalAmount)

Solutions

Expert Solution

def getSum(item1, item2, item3, item4, item5):
    return item1 + item2 + item3 + item4 + item5

def getTotalTax(subtotal):
    return subTotal * .06

def getTotalAmount(subTotal, totalTax):
    return subTotal + totalTax

def main():
    # Enter price for Item1
    item1 = float(input('Enter the price for item1: '))

    # Enter price for Item2
    item2 = float(input('Enter the price for item2: '))

    # Enter price for Item3
    item3 = float(input('Enter the price for item3: '))

    # Enter price for Item4
    item4 = float(input('Enter the price for item4: '))

    # Enter price for Item5
    item5 = float(input('Enter the price for item5: '))

    print()

    # Calculate the total owed before tax
    subTotal = getSum(item1,item2,item3,item4,item5)
    print('The subtotal of the items is: ', subTotal)

    # Calculate the total tax amount owed
    totalTax = getTotalTax(subTotal)
    print('The total tax owed is: ', totalTax)

    # Calculate the total amount owed
    totalAmount = getTotalAmount(subTotal, totalTax)
    print('The total amount owed is: ', totalAmount)

main()


Related Solutions

CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
Calculating Delivery Cost Program in Python write a program in Python that will ask a user...
Calculating Delivery Cost Program in Python write a program in Python that will ask a user to enter the purchase total, the number of the items that need to be delivered and delivery day. Then the system displays the cost of delivery along with the total cost. Purchase total > $150 Yes Number of the items (N) N<=5 N>=6 Delivery day Same Day Next Day Same Day Next Day Delivery charges ($) 8 N * 1.50 N * 2.50 N...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Write a GUI based Python program that will allow the user to perform (i) generate RSA...
Write a GUI based Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as well....
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
In python, write a program that asked the user to enter the monthly costs for the...
In python, write a program that asked the user to enter the monthly costs for the following expenses incurred from operating his automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should display total monthly cost and annual cost. Also, should contain main and calcExpenses functions, calcExpenses should only calculate the expenses and everything else should happen in the main function.
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT