Question

In: Computer Science

Create a python program that contains a while loop together with a Sentinel (0) to process...

Create a python program that contains a while loop together with a Sentinel (0) to process indefinite item costs that are purchased online from a vendor. Be sure that you assign a variable SENTINEL to 0 to use in the Boolean condition of your while loop. A sales tax rate of 6.25% is applied to the subtotal for the items purchased. Be sure you assign a variable, TAXRATE to 0.0625.

The program is to process a number of items, numItems, of item costs, itemCost, purchased online to keep track of an indefinite number of items, numItems, purchased and a running subtotal, subTotal, of item costs, itemCost, purchased (entered by the user) until the user enters the sentinel value of 0 for itemCost to stop the processing. The itemCost is read from the keyboard as a floating point value. It is important that you initialize to zero both numItems and subTotal.

Outside of the while loop if the counter, numItems, is not zero, (1) determine the sales tax, salesTax, by multiplying the subTotal by the TAXRATE, (2) determine the total cost after tax, total, by assigning it to the addition of the salesTax to the subTotal, and finally (3) display at the screen the number of items purchased, the sub total, sales tax, and total of the purchase. All monetary values are to be formatted with commas and with two digits to the right of the decimal point. If no items (i.e. numItems is zero) were purchased, then your program is to send to the display an appropriate message such as: "Return when you have purchased items!".)

Solutions

Expert Solution


Given below is the code for the question. PLEASE MAKE SURE INDENTATION IS EXACTLY AS SHOWN IN IMAGE.
Please do rate the answer if it helped. Thank you.


numItems = 0
subTotal = 0
SENTINEL = 0
TAXRATE = 0.0625
itemCost = -1
while itemCost != SENTINEL:
   itemCost = float(input('Enter item cost (type 0 when done): '))
   if itemCost != SENTINEL:
       numItems += 1
       subTotal += itemCost

if numItems > 0:
   salesTax = TAXRATE * subTotal
   total = subTotal + salesTax
   print('No. of items = ', numItems)
   print('Sub Total = {0:,.2f}'.format(subTotal))
   print('Sales Tax = {0:,.2f}'.format(salesTax))
   print('Total = {0:,.2f}'.format(total))
else:
   print('Return when you have purchased items!')


Related Solutions

Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a...
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a sentinel value #This while loop ends when the user enters a 1, the sentinel value #Assign the number 8 to a variable which will serve as the sentinel value #Condition: while variable is not equal to 1 #Action: display the number assigned to the variable #Use an input statement (no prompt) to ask the user for a number and assign this number to the...
Sentinel While Loop Lab Convert Lab 11 from a counter controlled WHILE loop to a sentinel...
Sentinel While Loop Lab Convert Lab 11 from a counter controlled WHILE loop to a sentinel WHILE loop. Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User is done entering grades ELSE Count each grade as it is entered. Compute a running total of the grades entered. END IF After the user enters the sentinel of -1, calculate the average of...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve week program training to compete in a triathlon. The triathlon consists of three athletic events, 1.5 k swim, 40k bike, 10k run. In order to be prepared for the competition you want to print a training schedule. Starting with week 1 you will increase the distance of each activity so that you reach the race distance by week twelve. Due to rounding, you may...
Write a program in java that deliberately contains an endless or infinite while loop. The loop...
Write a program in java that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions with single-digit random integers. Users can answer the questions and get immediate feedback. After each question, the user should be able to stop the questions and get an overall result. See Example Output. Example Output What is 7 * 6 ? 42 Correct. Nice work! Want more questions y or n ? y What is 8 * 5 ? 40...
Java Program. Sentinel While Loop Lab Do the following: Prompts the user to enter a grade...
Java Program. Sentinel While Loop Lab Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User is done entering grades ELSE Count each grade as it is entered. Compute a running total of the grades entered. END IF After the user enters the sentinel of -1, calculate the average of the grades entered. When computing the average, make sure that there is...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Design a Python program with a While loop that lets the user enter a number. The...
Design a Python program with a While loop that lets the user enter a number. The number should be multiplied by 10 and the result stored in a variable named "product". The loop should repeat as long as the product variable < 10. Anything not completely obvious to a newbie should be commented on as in line comments. Should be modulated and repeatable as well as there should be an invocation of the main routine at the end of the...
Write a PYTHON program that uses a while loop to prompt for 5 integers. If the...
Write a PYTHON program that uses a while loop to prompt for 5 integers. If the number is equal to 99, display "Ninety-nine", otherwise display "no-match". If the number is equal to 75, display "Seventy-five", otherwise display "no-match".
2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
I have to use a sentinel while loop to complete the following task in a java...
I have to use a sentinel while loop to complete the following task in a java program, I want to see how this is executed so I can better understand how the sentinel while loop works. Thank you! Convert Lab 10 from a counter controlled WHILE loop to a sentinel WHILE loop. Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT