Skip to content

calculating the shipping order #12

Description

@mcbrighty

I decided to add Boolean variable to this code of solving it and whenever I ran my code I get additional $1 added if the total shipping order exceeds or equals $50. Why?
This is the code:

Program to calculate a shipping order and give a tip of free shipping if order exceeds $50 else $10 fee

shippingFee = False
sumTotal = 0

orderTotal = float(input("Enter the total amount of order "))
if orderTotal >= 50:
shippingFee = True
print("Shipping is free")

else:
shippingFee = 10
print("Shipping fee will cost additional $10")

sumTotal = orderTotal + shippingFee

print("Your total shipping fee with order is $%2f" % sumTotal)
print("Your total shipping fee with order is $" + str(sumTotal))

Activity

  1. izleogrenkodla commented on Aug 23, 2020

    @izleogrenkodla
  2. pjk302 commented on Aug 24, 2020

    @pjk302

    There are few issues with your code for the results that your seeking @mcbrighty .

    First, as @izleogrenkodla stated, in Boolean "True" has a value of "1", and the way Boolean is used in the code, the results simply added the value "1". In addition, the Boolean is being used backward, so the results would only add value of 1 for orders over 50 while adding value 10 for orders under 50. This occurs because: in code "if orderTotal >= 50:" when it should be "if orderTotal <= 50:" but still that would not change the fact that True adds the value "1" that required ensure appropriate variable added (see below example). There are a couple of smaller coding issues. Below I have provided two example codes, the first uses Boolean which will provide the results. But with the simple results that is being seek, I would use the "If/Else Statement which is cleaner and easier to use with numerical values--the second example code. Hopefully, they have been helpful. Thanks.

    Example 1 (Boolean)

    shipping fee to order

    example 1

    shippingFee = False
    sumTotal = 0

    orderTotal = float(input("Enter the total amount of order: "))

    if orderTotal <= 50: # changed >= to <=
    shippingFee = True
    shippingFee = 0 # added this variable to add 0 instead 1
    print("Shipping is free")

    else:
    shippingFee = 10
    print("Shipping fee will cost additional $10")

    sumTotal = orderTotal + shippingFee

    print("Your total shipping fee with order is ${0:.2f}".format(shippingFee))
    print("Your total order cost is ${0:.2f}".format(sumTotal))

    print()

    Example 2 (If/Else Statement)

    shipping fee to order

    use simple If Else statements

    Example 2

    sumTotal = 0

    orderTotal = float(input("Please enter total amount of order: "))

    if orderTotal <= 50:
    shipFee = 0
    print("Shipping is Free!")
    print()

    else:
    shipFee = 10
    print("Shipping fee will cost additional $10")
    print()

    sumTotal = orderTotal + shipFee

    print("Your order amount is: ${0:.2f}".format(orderTotal))
    print("You shipping cost is: ${0:.2f}".format(shipFee))
    print("You total order cost is: ${0:.2f}".format(sumTotal))

    print()

    Thanks!

  3. pjk302 commented on Aug 24, 2020

    @pjk302

    Sorry, indentation required in the appropriate sections, the formatting of this comment section does a poor job of reflecting actual code~ I could provide actual py files if necessary. Thanks! Patrick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions