I am trying to make a Shipping calculator in python by using IF Statements. The application should calculate the total cost of an order including shipping. I am stuck at a point where python just won't run my code at all. I have a feeling I'm close but I do not know what is wrong with what I'm inputting because python won't return any errors. please someone just steer me in the right direction.
Instructions:
Create a program that calculates the total cost of an order including shipping.
When your program is run it should ...
- Print the name of the program "Shipping Calculator"
- Prompt the user to type in the Cost of Items Ordered
- If the user enters a number that’s less than zero, display an error message and give the user a chance to enter the number again. (note: if you know loops/iterations, OK to use here, but if not, just a simple one-time check with an if statement will be OK here.) For example: if the cost is less than zero, print an error message and then re-ask once for the input.
Use the following table to calculate shipping cost: | Cost of Items | Shipping cost | | ------------- | ------------- | | <30 | 5.95 | | 30.00-49.99 | 7.95 | | 50.00-74.99 | 9.95 | | >75.00 | FREE |
- Print the Shipping cost and Total Cost to ship the item
- End the program with an exit greeting of your choice (e.g. Thank you for using our shipping calculator!)
Example 1:
================= Shipping Calculator
Cost of items ordered: 49.99
Shipping cost: 7.95
Total cost: 57.94
Thank you for using our shipping calculator!
Example 2:
================= Shipping Calculator
Cost of items ordered: -65.50
You must enter a positive number. Please try again.
Cost of items ordered: 65.50
Shipping cost: 9.95
Total cost: 75.45
Thank you for using our shipping calculator!
Here is the code I have written out so far:
#Assignment shipping calculator
#Author: Name
def main():
print("Shipping Calculator")
subtotal = calc_subtotal()
shipping = calc_shipping()
total = calc_total()
main()
def calc_subtotal():
subtotal = float(input("Cost of Items Ordered: $"))
if subtotal <= 0:
print("You must enter a positive number. Please try again.")
return subtotal
def calc_shipping():
subtotal = calc_subtotal()
shipping = calc_shipping
if subtotal >= 1 and subtotal <= 29.99:
shipping = 5.95
print("Shipping Cost: $5.95")
if subtotal >= 30 and subtotal <= 49.99:
shipping = 7.95
print("Shipping Cost: $7.95")
if subtotal >= 50 and subtotal <= 74.99:
shipping = 9.95
print("Shipping Cost: $9.95")
if subtotal >= 75:
shipping = 0
print("Shipping Cost: Free")
def calc_total():
total = calc_subtotal() + calc_shipping()
print("Total Cost: ",total)
print("Thank you for using our shipping calculator!")