← Back to team overview

sikuli-driver team mailing list archive

[Question #689084]: My code is not calculating sales discount.

 

New question #689084 on Sikuli:
https://answers.launchpad.net/sikuli/+question/689084

Hello everyone,
                         I am having problems getting my code to calculate sales discount.
I have modules that I imported; one of them is the sales price. I wonder if it has a direct effect on why the program is not calculating the sales discounts.
At the end of everything, it gives me $0.00, for the sub-total; $0.00 for the total discount, and $0.00 for the final price.

Please take a look at it for me.

The two imported modules are listed below, then the main Python code follows.
Thanks



# Project 4
# Chuka Ihemaguba
# The "RETAIL_PRICE" module

RETAIL_PRICE = 99



# Project 4
# Chuka Ihemaguba
# Welcome Shoppers

print("Welcome Shoppers!!!!!")
print("Below are the discounts on the product based on how many you buy.")
print("------------------------------------------------------------------\n")
print("Quantity of 100 or more items: 40% discount")
print("Quantity of 50-99 items: 30% discount")
print("Quantity of 20-49 items: 20% discount")
print("Quantity of 10-19 items: 10% discount")
print("Quantity of less than 10 items: No discount\n\n\n")











# Project 4
# Chuka Ihemaguba
# 3/1/20


# This program requests the number of packages bought.
# Then it calculates the discount, based on the stipulations.
# And then the program displays the discount amount, and
# the total amount after the discount


# Import statement
import R_Price, Welcome_shoppers


# Declaration statement
quantity_purchased = 0
discount = 0
sub_total = 0
total_discount = 0
total = 0


# Define the "main" function
def main():
    # Call the sub-functions
    quantity_purchased = Input_packages()
    discount = determine_discount()
    sub_total = calculate_fullprice(R_Price, quantity_purchased)
    total_discount = calculate_discount(sub_total, discount)
    total = final_price(sub_total, discount)
    Print_SDT()


# Define the "Input_packages" function
def Input_packages():
    # Get the quantity of packages from user
    qunatity_purchased = int(input('Quantity purchased: '))
    return qunatity_purchased


# Define the "determine_discount" function
def determine_discount():
    if quantity_purchased < 10:
        discount = 0    # No discount
    elif 10 <= quantity_purchased and qunatity_purchased < 20:
        discount = 0.1    # 10% off
    elif 20 <= quantity_purchased and qunatity_purchased < 50:
        discount = 0.2    # 20% off
    elif 50 <= quantity_purchased and qunatity_purchased < 100:
        discount = 0.3    # 30% off
    else:
        discount = 0.4    # 40% off
        return discount


# Define the "calculate_fullprice" function
def calculate_fullprice(R_Price, quantity_purchased):
    sub_total = R_Price.RETAIL_PRICE * quantity_purchased


# Define the "calculate_discount" function
def calculate_discount(num1, num2):
    total_discount = sub_total * discount
    return total_discount


# Define the "total" function
def final_price(num_A, num_B):
    total = sub_total - discount
    return total


# Define the "Print_SDT" function
def Print_SDT():
    print('Subtotal: ', '$', format(sub_total, ',.2f'))
    print('Discount: ', '$', format(total_discount, ',.2f'))
    print('Total: ', '$', format(total, ',.2f'))


main()

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.