Ice Cream Round 2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class IceCream(object):
    def __init__(self, flavor, numScoops, costPerScoop, remaining_icecream):
        self.flavor = flavor
        self.numScoops = numScoops
        self.costPerScoop = costPerScoop
        self.remaining_icecream = remaining_icecream

    def scoop(self):
        #scoops icecream and decreases the number of scoops left
        self.remaining_icecream -= self.numScoops
        return self.remaining_icecream

    def total_cost(self):
        #vanilla ice cream is sold at a discount of half off!
        if self.flavor == "vanilla":
            total_cost = self.numScoops * .5*self.costPerScoop

        else:
            total_cost = self.numScoops * self.costPerScoop

        return total_cost

Using Python, which of the following methods could be added to the class IceCream to print out the size of the order based on the number of scoops where 1 to 3 scoops is a small, 4 to 5 is a medium, and more than that is a large.

1
2
3
4
5
6
7
def sizeA(self):
    if self.numScoops in range(1,3):
        print "small"
    elif self.numScoops in range(4,5):
        print "medium"
    else:
        print "large"

1
2
3
4
5
6
7
def sizeB(self):
    if self.numScoops in range(1,4):
        print "small"
    elif self.numScoops in range(4,6):
        print "medium"
    else:
        print "large"

1
2
3
4
5
6
7
def sizeC(self):
    if numScoops in range(1,4):
        print "small"
    elif numScoops in range(4,6):
        print "medium"
    else:
        print "large"

1
2
3
4
5
6
7
def sizeD(self):
    if scoops in range(1,4):
        print "small"
    elif scoops in range(4,6):
        print "medium"
    else:
        print "large"

(ignore the fact that these functions may return None along with the size printed)

×

Problem Loading...

Note Loading...

Set Loading...