[Tutor] taking a tuple with input

2013-10-26 Thread Sven Hennig
Hey Guys,

i'm running Python 3.3.2 on Windows 7 64 Bit

I am writing a little script for practice and got a little problem.
I wrote a class which got two points in the constructor (p1 and p2). With
the function distanceOf from my class i measure the distance between these
two points. Everything works fine. But when i want to use input to get the
points i does not work...

So how can i get an int tuple with input?

Some Code:

class points:
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def distanceOf(self):
diff = (self.p2[0] - self.p1[0], self.p2[1] - self.p1[1])
a = diff[0]
b = diff[1]
result = math.sqrt(a**2 + b**2)
return "The distance between the two points:", round(result)

When i type test = points((25.0, 30.0), (40.0, 55.0)) and test.distanceOf()
everything is ok. Now i wont to get input. (In the input prompt i write:
(25.0, 30.0)
p1 = input('Please type in some coordinates')
p2 = input('Please type in some coordinates')
test = points(p1, p2)
points.distanceOf()

Traceback (most recent call last):
  File "lines.py", line 16, in 
line.distanceOf()
  File "lines.py", line 6, in distanceOf
diff = (self.p2[0] - self.p1[0], self.p2[1] - self.p1[1])
TypeError: unsupported operand type(s) for -: 'str' and 'str'

i get this error

can anyone help me out? How can i get an tuple with int values from user
input?

Greetings
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginner Question

2013-10-22 Thread Sven Hennig
Thank you! You guys helped me out alot.

@Alan your website is great! Really clearly written. Especially the "Things
to remember" part.

If you have exercises for me or have a Website with exercises, bring it on. I
think this is the best way to learn.



2013/10/22 Dave Angel 

> On 22/10/2013 10:25, Sven Hennig wrote:
>
> >  Hello, I would like to learn a programming language and have decided to
> use
> > Python. I have some programming experience and doing well in Python. What
> > really causes me problems is OOP.
> > I'm just dont get it... I'm missing a really Practical example. In every
> > book I've read are the examples of such Class Dog and the function is
> bark. Has
> > anyone an OOP example for me as it is really used in real code, so I can
> > better understand the concept? I do not know why this is so hard for me.
> >
>
> What you may not realize is you're already doing OOP, just by using the
> standard library.  When you open a file (or many other things that can
> produce a stream of bytes), you get an instance of class file.  When you
> use that instance, you're calling methods of that instance.  So when you
> say:
>
> infile = open("myfile.txt,"r")
> data = infile.readline()
>
> you're doing object oriented programming.  You don't have to know what
> kind of thing "infile" is, you just have to know it has methods read(),
> readline(), close(), etc.
>
> When you want to write your own classes, or when you want to make a new
> class that's related but different from one of the thousands that are
> standard, that's when it gets interesting.  As Alan says, GUI is one
> place where you'll be wrting your own classes, usually by deriving from
> one of the GUI library classes.
>
> At its most fundamental, a class is a description of how to create and
> how to manipulate instances.  An instance has methods (functions), and
> attributes (data).  When one class is derived from another, it can share
> some or most of the attributes and behavior of the parent class, but
> make changes.  This helps avoid duplicating code when two things are
> similar.
>
> You're familiar with list and tuple.  Those are built-in
> collection classes, supported explicitly by the language. But if you
> want your own collection, you may want to make a class for it.  The Dog
> bark() example may seem silly, but a Dog has lots of other methods
> besides that one, and has lots of attributes (color, breed, health
> state, owner, etc.).  In a sense those attributes are like a list within
> the Dog, but you want them to have nice names, instead of remembering
> that the 3rd one is owner.
>
>
> --
> DaveA
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Beginner Question

2013-10-22 Thread Sven Hennig
 Hello, I would like to learn a programming language and have decided to use
Python. I have some programming experience and doing well in Python. What
really causes me problems is OOP.
I'm just dont get it... I'm missing a really Practical example. In every
book I've read are the examples of such Class Dog and the function is bark. Has
anyone an OOP example for me as it is really used in real code, so I can
better understand the concept? I do not know why this is so hard for me.

Greetings
Sven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor