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
#3
If your wanting to add a string to the return, you can do this
#! /usr/bin/env python3
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, 'Ground Shipping' # Add string to return

  elif (drone_ship < ground_ship) and (drone_ship < premium_ground_price): # drone_ship
    return drone_ship, 'Drone Shipping' # Add string to return

  elif (premium_ground_price < ground_ship) and (premium_ground_price < drone_ship): #premium_ground_price
    return premium_ship, 'Premium Shipping' # Add string to return


step_6 = method_is_cheapest(4.8)
#access the return index
print_string = f'Ship Price: {step_6[0]} Cheapest ship method: {step_6[1]}'
print(print_string)
Output:
Ship Price: 19.2 Cheapest ship method: Ground Shipping
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: return string from function with one argument - by menator01 - May-28-2020, 11:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 425 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  nested function return MHGhonaim 2 562 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,175 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  function return boolean based on GPIO pin reading caslor 2 1,131 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,033 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,776 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,763 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,421 May-13-2022, 07:28 PM
Last Post: mikepy
  return vs. print in nested function example Mark17 4 1,674 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  Regex - Pass Flags as a function argument? muzikman 6 3,485 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