Python Forum
simple function problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple function problem
#1
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
Yoriz write Apr-25-2021, 03:29 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Please see Homework and No Effort Questions
Reply
#3
(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
Reply
#4
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
Reply
#5
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))
Reply
#6
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple animation -- time evolution of function schniefen 0 1,020 Nov-20-2022, 08:05 PM
Last Post: schniefen
  I have a simple problem ahmed 5 2,505 Jul-17-2021, 02:50 PM
Last Post: ahmed
  Simple problem with functions and returns danlopek14q 10 6,696 Mar-17-2021, 05:32 PM
Last Post: danlopek14q
  Problem with a simple script Niko047 2 3,322 Jul-21-2017, 09:02 PM
Last Post: Niko047

Forum Jump:

User Panel Messages

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