Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculating the shipping order #12

Open
mcbrighty opened this issue Aug 22, 2020 · 3 comments
Open

calculating the shipping order #12

mcbrighty opened this issue Aug 22, 2020 · 3 comments

Comments

@mcbrighty
Copy link

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))

@izleogrenkodla
Copy link

izleogrenkodla commented Aug 23, 2020 via email

@pjk302
Copy link

pjk302 commented Aug 24, 2020

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!

@pjk302
Copy link

pjk302 commented Aug 24, 2020

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants