Python Forum

Full Version: simple function problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def fruit(melon, pear) :
(

)
  return result
print(fruit(10, 5))
print(fruit(6, 4)) 
hey guys, i'm trying to make a calculation for a fruit store.

Below is the given information:
Price of melon is 1000 and peark is 3000
if you buy more than 10 melon you get a 50%discount on pear.

Could you tell me the code that I should put in between ()? without making any changes on the given code. Thanks
(Apr-25-2021, 03:22 PM)stereokim123 Wrote: [ -> ]
def fruit(melon, pear) :
(

)
  return result
print(fruit(10, 5))
print(fruit(6, 4)) 
hey guys, i'm trying to make a calculation for a fruit store.

Below is the given information:
Price of melon is 1000 and peark is 3000
if you buy more than 10 melon you get a 50%discount on pear.

Could you tell me the code that I should put in between ()? without making any changes on the given code. Thanks
write your own code and I will help you dude
Is this assignment actually worded like that? The text says you get a discount "on pear" when you buy MORE than 10 melons but the example code only buys 10 melons so it never triggers the discount. Did you mean "10 or more"? Also, it reads like you get discount on any amount of pears after you buy 10 melons. Seems like you should only get a discount on ONE pear for every 11 (or is it 10?) melons. That's a bit more complicated to code so make sure you're explaining the question correctly.

And where can you buy pears cheaper than melons anyway??? Think
def fruit(melon, pear):

    # melon price
    global melon_price
    melon_price = melon * 1000

    # pear price
    if melon >= 10:
        pear_price = (3000 * 0.5) * pear
    else:
        pear_price = 1000 * pear
    return pear_price, melon_price


print(fruit(10, 5))
print(fruit(6, 4))
def fruit(melon, pear):
    if melon > 10: return (melon*1000, pear*1500) # return total cost after discount
    return (melon*1000, pear*3000) # return total cost without discount
print(fruit(10, 5))
print(fruit(6, 4))