Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BEFORE DOING THIS LOOK DOWN AT THE GRADING RUBIC. For my name you can enter JASO

ID: 3537136 • Letter: B

Question

BEFORE DOING THIS LOOK DOWN AT THE GRADING RUBIC. For my name you can enter JASON


Software Sales

Quantity

Discount

10-19

20%

20-49

30%

50-99

40%

100 or more

50%

A software company sells a package that retails for $99. Quantity discounts are given according to the following table: F

Write a program that asks the user to enter the number of packages purchased. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount.

Screen captures of a number of program execution runs with varying input counts.

Screen Captures

Calculations:

>>>

CSC 122 Program #3

By Carol Coder

Due Tuesday June 4th

Enter the number of packages purchased: 5

Discount Amount: $0.00

Total Amount: $495.00

>>>

Retail price = 5 * 99 = $495

Discount Amt = 0

Total amount = Retail price - Discount Amt = $495.00

CSC 122 Program #3

By Carol Coder

due Tuesday June 4t h

Enter the number of packages purchased: 10

Discount Amount: $1455.30

Total Amount: $3395.70

>>>

Retail price = 10 * 99 = $990

Discount Amt = 20% * $990 = $198.00

Total amount = 990-198 =$ 792.00

CSC 122 Program #3

By Carol Coder

due Tuesday June 4t h

Enter the number of packages purchased: 49

Discount Amount: $1455.30

Total Amount: $3395.70

>>>

Retail price = 49 * 99 = $4851

Discount Amt = 30% * $4851 = $1455.30

Total amount = 4851-1455.30 = $3395.70

CSC 122 Program #3

By Carol Coder

due Tuesday June 4t h

Enter the number of packages purchased: 99

Discount Amount: $3920.40

Total Amount: $5880.60

>>>

Retail price = 99 * 99 = $9801

Discount Amt = 40% * $9801 = $3920.40

Total amount = 9801-3920.40= $5880.60

CSC 122 Program #4

By Carol Coder

due Thursday Oct. 20th

Enter the number of packages purchased: 100

Discount Amount: $4950.00

Total Amount: $4950.00

>>>

Retail price = 100 * 99 = $9900

Discount Amt = 50% * $9900 = $4950.00

Total amount = 9900 -4950.00= $4950.00

Additional program requirements:

1.   Your program must use a function to print out your standard output header information. No arguments are required for this function.

2. Your program defines and initializes Global constants for the retail price of $99.

3.   Your program defines and calls a function to determine the discount amount based on the quantity input by the user. This function named getDiscount in my algorithm below is passed the quantity input by the user, and returns the appropriate discount based on the discount table on the first page. (You will use come combination of if else statements to calculate the discount amount for the quantity passed in as a parameter.)

4.   Your program defines and calls a function to print out with labels, the Discount Amount and the Total Amount. This function should be passed as arguments the discountAmount and totalAmount which were calculated in the main program. This information is printed with a descriptive label $ and to two decimal points output.

Grade Rubric:

Points

Task

10

Your program uses and calls a function to print out standard program header information.

CSC 122 Program #3

Your Name

Due Date: Tuesday June 4th

5

Your program includes comments.

10

Your program declares global constants as specified above.

5

Your main program prompts the user to input the number of packages purchased.

40

You have defined a function to return the discount amount when it is passed as parameter, the number of packages purchased. The correct value is calculated and returned to the main calling program.

10

Your main program correctly calculates the total amount

20

Your program uses a function which is passed arguments for:

discountAmount and totalAmount and prints out the data with labels and formatting.

100

Total Points


EXAMPLE LAYOUT POSSIBILITIES


t


# CSC 122 Program 3 Software Sales

# Named constants

RETAIL_PRICE = 99

def printHeader():

#Your output header statements here

def getDiscount(quantity):

# Calculate the discount rate

# Use if statements here to test quantity to determine amount of discount earned

      return discount

     

# The showPurchase module accepts discountAmount, totalAmount as

# arguments and displays the amounts

def showPurchase(discountAmount, totalAmount):

     

# main module

# Local variables

quantity = 0

discount = 0.0

discountAmount = 0.0

totalAmount = 0.0

# Print Header

printHeader()

# Get number in variable quantity

#call function to determine that appropriate discount for quantity input

discount = getDiscount(quantity)

     

# Calculate the discount amount

#Calculate the total amount

# call showPurchase to print results

showPurchase(discountAmount, totalAmount)




Quantity

Discount

10-19

20%

20-49

30%

50-99

40%

100 or more

50%

Explanation / Answer

Refer the code from above.

for comments, I m typing the code here again


#!/usr/bin/python3

def main():

packages = int(input('Number of packages : '))

//storing the number of packages bought in a variable called packages.

//it is typecasted to int. If you don't , then it will be taken as String type by default


if packages <= 19 and packages >= 10:

// if no of packages bought is in the range 10 to 19,

discount(packages, .2)

// then calling a function discount(packages, .2)

//where first parameter is no of packages bought and the second parameter is 20% of //discount

elif packages <= 49 and packages >= 20:

// if no of packages bought is in the range 20 to 49,

discount(packages, .3)


// then calling a function discount(packages, .3)

//where first parameter is no of packages bought and the second parameter is 30% of //discount




elif packages <= 99 and packages >= 50:


//// if no of packages bought is in the range 50 to 99,



discount(packages, .4)


// then calling a function discount(packages, .4)

//where first parameter is no of packages bought and the second parameter is 40% of //discount


else:

discount(packages, .5)

// if 100 and above then

// then calling a function discount(packages, .5)

//where first parameter is no of packages bought and the second parameter is 50% of //discount




def discount(value, x):


// function

print('You receive a %f discount' % x)

discount = reg * value * x

// calculating the total discount where reg = 99, value = value of packages called from main

// x is the percentage of discount

print('Discount Amount $', discount)

//printing the discount amount

total = (reg * value) - discount

// finding the total price after discount

print('Total Amount $', total)

// printing the total value

reg = 99


// assigning reg to 99

main()