View difference between Paste ID: UZcD6LF9 and UX3t03vD
SHOW: | | - or go back to the newest paste.
1
# Use docstrings.
2
# http://docs.python.org/tutorial/controlflow.html#intermezzo-coding-style
3
# http://www.python.org/dev/peps/pep-0257/
4
##random needed for mix method.  Needs to be external to the class 
5
import random
6
7
class Bowl:
8
    ##with a little help from: http://stackoverflow.com/questions/227459/ascii-value-of-a-character-in-python
9-
    ##Constructor!
9+
10-
    ##sorry to change your code, Sean but this allows Bowl to be treated as a list
10+
11-
    def __init__(self, values = None):
11+
12-
        self.values = []
12+
    def __init__(self, values = []):
13
    	"""sorry to change your code, Sean but this allows Bowl to be treated as a list"""
14-
    ##Length
14+
        self.values = values
15-
    ##returns length of Bowl
15+
16
    def __len__(self):
17
    	"""returns length of Bowl"""
18
        return len (self.values)
19-
    ##deletes the item at key in self
19+
20
    def delitem(self, key):
21
    	"""deletes the item at key in self"""
22
        del self.values[key]
23-
    ##returns the last element in self.values. (top of the stack)
23+
24
    def top(self):
25
    	"""returns the last element in self.values. (top of the stack)"""
26
        return self.values[len(self.values)-1]
27-
    ##appends value to self 
27+
28
    def put(self, ingredient):
29
    	"""appends value to self"""
30
        self.values.append(ingredient)
31-
    ##sets value of the top of the stack to ingredient     
31+
32
    def fold(self, ingredient):
33
    	"""sets value of the top of the stack to ingredient"""
34
        self.values[-1] = ingredient
35-
    ##This adds the value of ingredient to the value of the ingredient
35+
36
37
    def add(self, ingredient):
38
    	"""    ##This adds the value of ingredient to the value of the ingredient
39
    ##on top of the bowl and sets that sum as the new top of the stack,
40
    ##erasing what was there.
41
    	"""
42
        holder = self.top()
43-
    ##This subtracts the value of ingredient from the value of the ingredient
43+
44
        self.values[-1] = holder
45
46
47
    def remove(self, ingredient):
48
    	"""##This subtracts the value of ingredient from the value of the ingredient
49
    ##on top of the bowl and sets that difference as the new top of the stack,
50
    ##erasing what was there.
51-
    ##This multiplies the value of ingredient from the value of the ingredient
51+
    	"""
52-
    ##on top of the bowl and sets that product as the new top of the stack,
52+
53
        holder = holder - ingredient
54
        self.values[-1] = holder
55
56
    def combine(self, ingredient):
57
    	"""This multiplies the value of ingredient from the value of the ingredient
58
on top of the bowl and sets that product as the new top of the stack, erasing what was there.
59-
    ##This divides the value of ingredient from the value of the ingredient
59+
    	"""
60-
    ##on top of the bowl and sets that quotient as the new top of the stack,
60+
61
        holder = holder * ingredient
62
        self.values[-1] = holder
63
64
65
    def divide(self, ingredient):
66
        """This divides the value of ingredient from the value of the ingredient
67-
    ##This randomises the order of the ingredients
67+
        on top of the bowl and sets that quotient as the new top of the stack, erasing what was there.
68
    	"""
69
        holder = self.top()
70
        holder = holder / ingredient
71
        self.values[-1] = holder
72
73-
                True
73+
74
    	"""This randomises the order of the ingredients"""
75
        pretend = []
76
        while(len(self.values)>len(pretend)):
77
            holder = random.choice(self.values)
78-
##    This turns all the ingredients in the 
78+
79-
##    bowl into a liquid, i.e. a Unicode characters for output purposes.
79+
                pass
80
            else:
81
                pretend.append(holder)
82
        self.values = pretend 
83
84
    def liquify(self):
85
    	"""This turns all the ingredients in the bowl into a liquid, i.e. a Unicode characters for output purposes."""
86-
    ##to string method, so one can print Bowl when needed 
86+
87
        for x in range (len(self.values)):
88
            better.append(chr(self.values[x]))
89
        self.values = better
90
91
    ##
92
    def __str__(self):
93
    	"""to string method, so one can print Bowl when needed """
94
        return str(self.values)