Question

PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields...

PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields (item name and cost) and calculates and displays the calculated costs. The program should do the following: Provide data entry areas for item name and cost. Calculate and display the subtotal of all items. Adds a sales tax of 6% and calculate and displays the total cost.

Enter the following values into your program.

Mother Board $200. RAM $75. Hard Drive $72. Video Graphics Card $55.

Take a screenshot of your code and its results and paste into the Word document

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the python code for the above Question. You may edit it according to your need :

# We create two empty lists, item[] and cost[] to store the item name and their costs respectively.
# The subtotal and grand total variables store the computed total of the item costs before and after added tax.
# The option variable holds the input value when user is asked to continue or end adding items. 'Y' for yes and 'N' for no.
item=[]
cost=[]
subtotal=0
grandtotal=0  
option='Y'
# We try to emulate a do while loop in python as it does not have a do while loop as such.
# The loop continues till the if condition is not true and break statement is encountered.
while True :
   #The append() method appends a value to the end of the list specified. In this this case the item[] and cost[] lists.
   item.append(input("Enter item name :"))
   c=input("Enter item cost :")
   # Since the cost input is a string with a '$' symbol , we need to skip it and store the number part of the input.
   # The .index()method finds the index on the string where the specified character is present.
   # In this case we ought to find the '$' symbol and skip it. Thus we add 1 to the index it was found on.
   # Once the numbers are found they are converted to floating points from string type for arithmetic calculation.
   # The reason for conversion is that the input() function in python excepts input as string type by default.
   # Any spaces after the '$' symbol are automatically skipped while conversion from string to float.
   # Here we convert the costs to float type but not int type as int type truncates the decimal part and costs my contain decimal values.
   cost.append(float(c[c.index('$')+1:]))
   # We ask the user if he/she wants to continue adding items to the list.
   option=input("Do you want to add another item [Y/N]: ")
   # If the input is N (representing no as mentioned above), we break from the loop and exit it.
   if option == 'N':
       break
# Providing a line break for a clean output
print("\n")
# This loop prints the items serially along with their individual costs.
# Loop also calculates subtotal of all the items cumulatively that is subtotal= cost 1 + cost 2 + cost 3......
for i in range(len(item)) :
   print(i+1,item[i],"= $",cost[i],)
   subtotal=subtotal+cost[i]
# The grandtotal represents the total cost on the bill after the tax has been applied.
# The tax is applied on the bare subtotal of all the items' costs .
grandtotal= subtotal+0.06*subtotal

# We finally print the subtotal and grandtotal.
print("Subtotal = $",subtotal,"\n")
print("Grandtotal = $",grandtotal)

CODE SCREENSHOT:

OUTPUT SCREENSHOT :

Add a comment
Know the answer?
Add Answer to:
PYTHON Programming Exercise 2: Create a Simple Cost Calculator Write a program that displays input fields...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...

    DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a function called inch2cm that takes one number in inches as a parameter, converts it to the centimeters and prints the result. The program output is shown below. Input: 14 Output: 14 inches = 35.56 centimeter Write a program and create the following functions: shapes(): takes the shape name and a number as parameters, and calls the proper function to calculate the area. areaCircle(): take...

  • Python Simple Programming Write a program in Python that calculates the tip and total for a...

    Python Simple Programming Write a program in Python that calculates the tip and total for a meal at a restaurant. When your program is run it should ... Calculate the tip and total for a meal for a restaurant Print the name of the application "Tip Calculator" Get input from the user for cost of meal and tip percent Print the tip and total amounts. The formula for calculating the tip amount is: tip = cost of meal * (tip...

  • Project overview: Create a java graphics program that displays an order menu and bill from a...

    Project overview: Create a java graphics program that displays an order menu and bill from a Sandwich shop, or any other establishment you prefer. In this program the design is left up to the programmer however good object oriented design is required. Below are two images that should be used to assist in development of your program. Items are selected on the Order Calculator and the Message window that displays the Subtotal, Tax and Total is displayed when the Calculate...

  • Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back...

    Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back in the archives of the Equinox history database. It is the specification for a simply "computer store storefront". Even though computer stores are now extinct, you find the idea charming and decide to use the specification as inspiration to write an interface for one of the Equinox systems. Read carefully: write your own GUI for one of the Equinox systems, drawing inspiration from the...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT