mercredi 29 juillet 2020

Returning NoneType from If Else - Cant determine why

I'm brand new to coding (and stack overflow) and just starting out so I apologise for the really basic question.

I am struggling to figure out why this if-else block isn't working.

The determine_cost function is returning a NoneType when it should be returning a float and I believe it has something to do with the shipping_method variable, but even with intensive googling, I can't seem to find a solution or why it's returning that.

I have tried calling the function without using the input lines and it seems to work okay, which indicates that it could have something to do with the input, but I can't figure what I'm doing wrong.

Any help would be appreciated.

def ground_shipping(weight):
    flat_charge = 20.00
    if weight > 10:
        ppp = 4.75
    elif weight > 6:
        ppp = 4.00
    elif weight > 2:
        ppp = 3.00
    else:
        ppp = 1.50
    return flat_charge + ppp


def prem_ground_shipping(weight):
    return 125.00


def drone_shipping(weight):
    if weight > 10:
        ppp = 14.25
    elif weight > 6:
        ppp = 12.00
    elif weight > 2:
        ppp = 9.00
    else:
        ppp = 4.50
    return ppp


def determine_cost(shipping_method, weight):
    if 1 == shipping_method:
        cost = ground_shipping(weight)
        return cost
    elif 2 == shipping_method:
        cost = prem_ground_shipping(weight)
        return cost
    elif 3 == shipping_method:
        cost = drone_shipping(weight)
        return cost


weight = input("Welcome to Sals Shipping! This calculator will help us determine how much your shipping will "
               "cost. To begin, how much does your item weigh in kg?\n")
shipping_method = input('Thanks! Next, what method of delivery best suits you? Enter 1 for our Ground Shipping '
                        'option. 2 for our Premium Ground shipping. Or 3 for our new Drone Shipping option.\n')
cost = determine_cost(shipping_method, weight)
print("Your item will cost: $" + str(cost))

Aucun commentaire:

Enregistrer un commentaire