0

say for example the first 5 apples you buy cost .50 and the next 5 apples you buy after that cost .40 and every apple after that is .30.

How would I go about creating a function that could tell okay apples 1-5 cost .50 then add any extra in range 5-10 for the value of .40 and then every apple after that costing .30?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by straylight
0

Does this functionality have to be incorporated in the function itself? It doesn't seem like something you'd want to use a function for at all. The functions are meant to not be aware of the global operations of the program, so it's not straightforward to have the function be aware of an iterable in the main program. Why exactly to you wan to use a function?

0

Yes this is just 1 function out of 4.. this one receives the values from function 1 then relays them to the 4th function and so on. It is part of a hw assignment i am working on.

This is what I have so far. It produces the right answer but it just feels real clunky.

gearboxes=30

if (gearboxes<=10):
        cost=gearboxes*100.0
        print cost
elif (gearboxes>10 and gearboxes<20):
        cost=(gearboxes-10)*80.0+1000.0
        print cost
elif (gearboxes>20):
        cost=(gearboxes-20)*70.0+1000.0+800.0
        print cost
else:
        print "wtf m8"

Edited by straylight: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.