Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pretext/Introduction/ObjectOrientedProgrammingDefiningClasses.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,22 @@ int main() {
<task xml:id="showmethod-py" label="showmethod_py">
<title>Python</title>
<statement><program interactive="activecode" language="python" label="showmethod_py-prog"><input>
def show(self):
print(self.num,"/",self.den)
class Fraction:

def __init__(self,top = 0,bottom = 1):

self.num = top
self.den = bottom
def show(self):
print(self.num,"/",self.den)
# main code below
fraca = Fraction(3,5)
fracb = Fraction(3)
fracc = Fraction()# notice no parameters are passed
# notice print(fraca) will give you an unexpected output
fraca.show()
fracb.show()
fracc.show()
</input></program></statement>
</task>
</exploration>
Expand Down