Python Forum
return string from function with one argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
return string from function with one argument
#1
def ground_shipping_cost(weight):
  cost = weight * 4.00
  return cost

#print(ground_shipping_cost (8.400)+20)

def drone_shipping_cost(weight):
  cost = weight * 4.50
  return cost

#print(drone_shipping_cost (1.5)) # static

def method_is_cheapest(weight):

  ground_ship = ground_shipping_cost (weight)
  drone_ship = drone_shipping_cost (weight)
  premium_ground_price = 125.00 # static

  if (ground_ship < drone_ship) and (ground_ship < premium_ground_price): # ground_ship is cheapest
    return ground_ship
  
  elif (drone_ship < ground_ship) and (drone_ship < premium_ground_price): # drone_ship
    return drone_ship
  
  elif (premium_ground_price < ground_ship) and (premium_ground_price < drone_ship): #premium_ground_price
    return premium_ship

"""
def method_price(weight):

  return price
"""

step_6 = method_is_cheapest(4.8)
    
print_string = "Ship price: " + str(step_6) + "Cheapest ship method: " + str(ship_method)"
print(print_string)

method_is_cheapest(100)
Hello all, i would like str(ship_method) to include a string from the return values (ground_ship, drone_ship, or premium_ship), whatever value is returned smallest from the calculation. I am very new to python coming from C
Reply


Messages In This Thread
return string from function with one argument - by jamie_01 - May-28-2020, 10:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 482 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  nested function return MHGhonaim 2 613 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,284 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  function return boolean based on GPIO pin reading caslor 2 1,183 Feb-04-2023, 12:30 PM
Last Post: caslor
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,093 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,861 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,877 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,525 May-13-2022, 07:28 PM
Last Post: mikepy
  return vs. print in nested function example Mark17 4 1,745 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  Regex - Pass Flags as a function argument? muzikman 6 3,597 Sep-06-2021, 03:43 PM
Last Post: muzikman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020