Python Forum
Get multiple values from function and total it.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get multiple values from function and total it.
#3
In P(), if someone orders 6 pizzas, that person gets charged for 8 because the remainder of 6 // 3 is not 1; PP() has the same issue.

To tack onto perfringo's critique, the functions are poorly done. They should have parameters instead of input inside of them. If P() is code like this:

pizza_prices = {
    0: 0.00,
    1: 10.99,
    2: 20.99,
    3: 29.99
}

def P(number, prices):
    price = prices.get(number, prices[len(prices) - 1])
    quotient = number // 3
    remainder = number % 3
    pizza_sales = (quotient * price) + prices[remainder]

    return pizza_sales, number, remainder, quotient

P(10, pizza_prices)
then it fixes the problem from before and is easy to update. You can provide any dict in the format of pizza_prices and change all the pricing. Plus, you can use P() for the pasta as well instead of having two separate functions since they are identical. Now, it still performs too much. If a function returns more than one value, it likely does too much.
Reply


Messages In This Thread
RE: Get multiple values from function and total it. - by stullis - Feb-03-2019, 03:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  __init__() got multiple values for argument 'schema' dawid294 4 2,475 Jan-03-2024, 09:42 AM
Last Post: buran
  Adding values with reduce() function from the list of tuples kinimod 10 2,724 Jan-24-2023, 08:22 AM
Last Post: perfringo
  How to combine multiple column values into 1? cubangt 15 2,896 Aug-11-2022, 08:25 PM
Last Post: cubangt
  function accepts infinite parameters and returns a graph with those values edencthompson 0 875 Jun-10-2022, 03:42 PM
Last Post: edencthompson
Sad Iterate randint() multiple times when calling a function Jake123 2 2,079 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Function - Return multiple values tester_V 10 4,492 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,523 Mar-09-2021, 12:24 PM
Last Post: KMV
  Looking for help in Parse multiple XMLs and update key node values and generate Out.. rajesh3383 0 1,886 Sep-15-2020, 01:42 PM
Last Post: rajesh3383
  function not giving back total SephMon 1 1,696 Aug-25-2020, 12:46 PM
Last Post: deanhystad
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,507 Aug-10-2020, 02:51 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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