Describing a code

This is the place for queries that don't fit in any of the other categories.

Describing a code

Postby ProDin » Thu Jan 23, 2014 3:42 am

I have a code produced but I was wondering how to describe each line of the code.

Code: Select all
class myCoord:
    def __init__(self, a, b):
        self.x = a
        self.y = b

class Line:
    def __init__(self, myCoord1, myCoord2):
        self.p1 = myCoord1
        self.p2 = myCoord2
    def calcLine(self):
        m = (self.p2.y - self.p1.y) / (self.p2.x - self.p1.x)
        c =(self.p1.y - (m*self.p1.x))
        if c>0:
            return('y=' + str(m) + 'x+' + str(c))
        if c<=0:
            return('y=' + str(m) + 'x' + str(c))

c2y = int(input('Enter the first coordinate y2 axis value:'))
c1y = int(input('Enter the first coordinate y axis value:'))
c2x = int(input('Enter the first coordinate x2 axis value:'))
c1x = int(input('Enter the first coordinate x axis value:'))

myCoord1 = myCoord(c2y, c1y)
myCoord2 = myCoord(c2x, c1x)
line = Line(myCoord1, myCoord2)
value = line.calcLine()
print(value)
Last edited by micseydel on Thu Jan 23, 2014 3:52 am, edited 1 time in total.
Reason: Locked OP.
ProDin
 
Posts: 4
Joined: Thu Jan 23, 2014 2:54 am

Re: Describing a code

Postby micseydel » Thu Jan 23, 2014 3:53 am

What do you mean "describe"? Is this a school assignment that you can post the exact wording to?
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1119
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Describing a code

Postby ProDin » Thu Jan 23, 2014 8:40 am

Thank you for your answer. What I mean by 'describe' is just basically say what each line of the code does. And no its not a school assignment therefore it doesnt have to be exact wording to
ProDin
 
Posts: 4
Joined: Thu Jan 23, 2014 2:54 am

Re: Describing a code

Postby micseydel » Thu Jan 23, 2014 9:00 am

A line-by-line description of this code would miss the point of much of it. It uses classes, which are a way to implement object-oriented programming, a high-level way of thinking that narrow focus on single lines wouldn't be adequate for capturing at the level a human is meant to understand the code.

So my question for you is: what do you know of programming? Why are you asking about this piece of code in particular? I think it would be best if you tried to describe the code yourself, and we filled in any gaps or provide any corrections. This will help us understand what we ought to be describing to you, since an absolute beginner programmer certainly would need the line-by-line for learning programming (and Python), but to do so on this code would be very, very confusing. This is the kind of code meant to be understood once you can handle individual lines by yourself.

If you do know zero programming, I would suggest you start here.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1119
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 4 guests