I just finished Advanced Python (and Basic & Intermediate before), so am testing my skills by creating a starting (portfolio) project, and also to keep building it out more to keep learning. I’m interested in creating a Courier Service Delivery Calculator, so similar to the one in Intermediate Python, Section 1 Function Arguments, Project ‘The Nile’, but much simpler.
Some differences:
this is for a bicycle courier, so all in one city
no difference in ‘rider cost’, no weight (will add in a future iteration)
no calculation of ‘daily’ total made, or subtracting driver cost from cost of delivery (maybe later)
a city is divided into only 3 zones to keep it simple (z.1 = $30, z.2 = $60, z.3 = $90), zone 1 in the center, zone 3 the farthest from the center
the cost of delivery is based on two zones (pick-up and delivery), the higher zone rate will be charged (a few examples: pick-up in zone 1 and deliver to zone 2 = $60, or, pick-up in zone 3 and deliver to zone 2 = $90, or, pick-up in zone 2 and deliver to zone 2 = $60)
but three levels of each (base (6-hour delivery), faster (3 hour delivery) and fastest (1 hour delivery); example: pick-up in zone 1 and deliver to zone 2 at the ‘faster’ rate (‘three_hours’) = $60 * 1.5 = $90
So, based on the ‘Nile’ project I slimmed it down and came up with this:
I don’t seem to get any major errors, but it also does not return a final tariff when I call the function.
I just copied over the ‘def format_price(price)’ but do not understand this, so most likely this needs to be adapted still. Also, the ‘get_rate’ is most likely incorrect.
If something is not clear, I can try and explain better.
Any help would be appreciated,
Thanks,
Mike
I decided to start from scratch, managed to get something working.
Next, will need to try and add ‘speed’ of delivery (base, faster, fastest), if I can figure that out then can also probably add weight.
I tried to do this as a nested function, but nothing seemed to work. Should I even be going in that direction? or should try in the direction of a Class(s)? Any recommendations as to the ‘best’ structure for future direction would be helpful.
Thanks,
Mike
finished = False
while finished == False:
print("Let's calculate the delivery tariff based on two zones")
pickup_zone = int(input("Pick-up zone is: "))
delivery_zone = int(input("Drop-off zone is: "))
zone1 = 30
zone2 = 60
zone3 = 90
def find_highest_zone():
if pickup_zone > delivery_zone and pickup_zone <=4:
return pickup_zone
elif delivery_zone > pickup_zone and delivery_zone <=4:
return delivery_zone
elif delivery_zone == pickup_zone and delivery_zone <=4:
return delivery_zone
# elif delivery_zone or pickup_zone >=4:
# return "Sorry, you entered an incorrect zone"
else:
return "Sorry, you entered an incorrect zone"
def calculate_rate():
if find_highest_zone() == 1:
print("Your rate is: " + str(zone1))
elif find_highest_zone() == 2:
print("Your rate is: " + str(zone2))
elif find_highest_zone() == 3:
print("Your rate is: " + str(zone3))
finished = True
else:
print("Sorry, that's not a correct zone, try again.")
print(calculate_rate())