Question

Lab Assignment Objectives: Translate a basic application statement into a software selection solution. Learn how to...

Lab Assignment Objectives:

  1. Translate a basic application statement into a software selection solution.
  2. Learn how to design and implement a simple program control structure.
  3. Use logical operators and boolean variables to set up test conditions.
  4. Construct applicable test cases to test your programs for correctness.

Understand the Application

You will obtain a grocery bill total from the customer. Depending on the amount of the grocery bill a coupon rewards amount will be calculated. The user will be informed of the amount of their earned customer rewards coupon.

The Program Specification

Your program will prompt the user for the cost of their groceries.

Then you are to calculate the value of the coupon to be awarded based on the amount of the grocery bill. Use the table below to determine coupon amounts.

Money Spent   Coupon Percentage
Less than $10   0%
From $10 to less than $60 8%
From $60 to less than $150 10%
From $150 to less than $210    12%
From $210 or more 14%

Display an appropriate result message to the user including both the coupon percentage awarded and the dollar amount of their discount coupon.

Testing Requirements

Input Error Checking: You can assume that when it is time for the user to enter a number to represent the amount of his/her day’s grocery bill that a valid numeric value will be typed in. You do not need to test for non-numeric nor negative values.  Note: A numeric 0 input is a valid data entry.

Be sure that your program runs correctly for each of these possible test cases: 0, 10, 70, 160, 222.

Here is a sample run (remember your program needs to work for all possible test case selections; your test run demonstration only needs to show one of the 5 possible test cases):

'''
Please enter the cost of your groceries: 160
You win a discount coupon of $19.20. (12% of your purchase)
'''

Tips and requirements:

  1. Create constants versus using literals in your source code.
  2. Use a float to represent both the shopper’s grocery bill as well as the coupon amount.
  3. Format the discount coupon amount to 2 decimal places (Example: $19.20).
  4. Show your program run for one of the test cases: 0, 10, 70, 160, 222. Note: Your program needs to work for all 5 test cases. Your program test run only needs to demonstrate one of the test cases.

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

Here is the code for your problem in PYTHON language

CODE :

NOTE : If you copy the code from answer , please remove comments and check if any dots added(this may occur while you copy) in a black background editor and check indentations twice.

#Creating variable for grocery_bills and asking user to enter bill amount

print("Please enter the cost of your groceries: ")

grocery_bill = float(input())

#NOTE : float(input()) will convert the bill to floating point

#Creating variable for coupon amount , initially set to 0

coupon_amount = 0.00
#Conditions to check for coupons
#If the bill amount is less than $10
if grocery_bill >= 0 and grocery_bill <10.00:
  
#Creating a variable to store discount percentage
#If condition true Zero discount will be rewarded
discount = 0.
#Grocery bill will not change
#If the bill amount is from $10 and less than $60
  
elif grocery_bill <= 10 and grocery_bill <60.00:
#8% discount is given
discount = 8
#Discount coupon amount is bill amount * discount/100
#This will be converted to float and rounded to 2 decimals
coupon_amount = round(float(grocery_bill * (discount/100)),2)
#If the bill amount is from $60 and less than $150
elif grocery_bill >= 60.00 and grocery_bill <150.00:
#10% discount is given
discount = 10
#Discount coupon amount is is bill amount * discount/100
#This will be converted to float and rounded to 2 decimals
coupon_amount = round(float(grocery_bill * (discount/100)),2)
#If the bill amount is from $150 and less than $210
elif grocery_bill >= 150.00 and grocery_bill <210.00:
#12% discount is given
discount = 12
#Discount coupon amount is is bill amount * discount/100
#This will be converted to float and rounded to 2 decimals
coupon_amount = round(float(grocery_bill * (discount/100)),2)
#If the bill amount is from $210 onwards
elif grocery_bill >= 210.00:
#14% discount is given
discount = 14
#Discount cuopon amount is is bill amount * discount/100
#This will be converted to float and rounded to 2 decimals
coupon_amount = round(float(grocery_bill * (discount/100)),2)

#Printing result
print("You win a discount coupon of ${0:.2f} ({1}% of your purchase)".format(coupon_amount,discount))
#We concatinating strings with other data types using format
#{} takes values of arguments from format
#{0.2f} takes first argument of format and print upto 2 decimals

Please see the screenshots of the code below for indentations.(Python language is strict at indentations)

SCREENSHOTS

OUTPUT

Demonstrating output for the test case - bill amount = 160.

1.The user will enter the value of grocery bill as 160

2.Assuming the user entered valid numerical value(as you mentioned not to test for non-numeric and negative values)

it will be checked against the conditions given above.

3.As 160 is between 150 and less than 210 discount of 12% is calculated on the bill amount 160

4.Formula to calculate discount percentage

FORMULA :

discount_amount = (bill amount) * (discount/100)

Here , discount amount is the variable coupon-amount ,

bill amount is the variable grocery_bill,

discount is the variable discount.

For grocery_bill = 160.00

coupon_amount = (160)*(12/100) = 19.20

5.Displays finally the discount amount and discount percentage as

  You win a discount coupon of $19.20(12% of your purchase)

OUTPUTS FOR ALL THE TEST CASES(0,10,70,160,222)


Add a comment
Know the answer?
Add Answer to:
Lab Assignment Objectives: Translate a basic application statement into a software selection solution. Learn how to...
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
  • A supermarket awards coupons depending on how much a customer spends on groceries. For example, if...

    A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth eight percent of that amount. The following table shows the percent used to caleculate the coupon awarded for different amounts spent. Write a program that calculates and prints the value of the coupon a person can receive based on groceries purchased. Here is a sample run: Please enter the cost of your groceries: 14 You...

  • Assignment #3 Introduction to C Programming-COP 3223 Objectives 1 Togve students practice at typing in, compiling...

    Assignment #3 Introduction to C Programming-COP 3223 Objectives 1 Togve students practice at typing in, compiling and nunning simple programs. 2 To reinforce knowledge of assignment statements and arithmetic expressions 3. To learn how to use if statements for conditional execution Introduction: Programmers for a Better Tomorrow Programmers for a Better Tomorrow is an organization dedicated to helping charities, medical societies, and scholarship organizations manage various tasks so that they can focus on making the world a better place! They...

  • Part II – Cost Calculator (15 Points) A software company sells a package that retails for...

    Part II – Cost Calculator (15 Points) A software company sells a package that retails for $ 99. Quantity discounts are given according to the following table: Quantity Discount 10 to 19 20% 20 to 49 30% 50 to 99 40% 100 or more 50% Write a program that asks the user to enter the number of packages purchased. The program should then display the discount percentage, amount of the discount (can be 0) and the total amount of the...

  • Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing...

    Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following:  Writing a while loop  Writing a for loop  Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the...

  • PROGRAM STATEMENT AND REQUIREMENTS: Great Tutors Inc. is a company that provides tutoring services to elementary...

    PROGRAM STATEMENT AND REQUIREMENTS: Great Tutors Inc. is a company that provides tutoring services to elementary school students. Parents bring their students after school to their offices where one tutor is assigned to each student. The same tutor is assigned to the student for every visit. A tutor teaches his/her assigned student for several hours and charges a flat rate per hour for any student. Each tutor can only teach for a maximum of 40 hours. The program must ask...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you...

    Java Program Note: no break statements or switch staements High, Low, Sevens For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------...

  • Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate...

    Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then ask you what time the car left the parking deck. You should then calculate the time that has passed between...

  • I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if,...

    I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if, switch, and loop statements to solve a problem. Use input and output statements to model a real world application Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then...

  • just the extra credit part please Your customer needs an automated system to patrol the highways....

    just the extra credit part please Your customer needs an automated system to patrol the highways. The job of the system is to collect the following information on vehicles traveling down a certain stretch of highway: license plate number, current speed, and speed limit. A program is required to determine if a speeding ticket is needed for each set of data. Ticket will only be issued when number of miles per hours (mph) over the speed limit is at least...

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