Computer Science Canada Methods Java to Python help? |
Author: | Kenster102.5 [ Mon Nov 02, 2009 10:21 am ] | ||||
Post subject: | Methods Java to Python help? | ||||
I have recently gotten started into Python, and am still very new at it, but I already have programing knowledge in Java and Turing. My question is I have this Java program using Instance and Constructor methods, and am trying to re-write it in Python, but I really can't figure out what I am doing wrong. Java Code:
Python Code:
So what must I do differently? Thanks Ken |
Author: | wtd [ Mon Nov 02, 2009 5:40 pm ] |
Post subject: | RE:Methods Java to Python help? |
It's worth noting that nowhere do you set up the num and den instance variables. |
Author: | Kenster102.5 [ Tue Nov 03, 2009 7:13 am ] |
Post subject: | Re: RE:Methods Java to Python help? |
wtd @ Mon Nov 02, 2009 5:40 pm wrote: It's worth noting that nowhere do you set up the num and den instance variables.
Ah, but sir they are stated as instance fields for the class Fraction. |
Author: | wtd [ Tue Nov 03, 2009 11:48 am ] | ||
Post subject: | RE:Methods Java to Python help? | ||
|
Author: | Kenster102.5 [ Wed Nov 04, 2009 10:03 am ] | ||||
Post subject: | Re: RE:Methods Java to Python help? | ||||
wtd @ Tue Nov 03, 2009 11:48 am wrote:
Okay? Do I always have to do self.a = a or self.num = num for instance methods in Python, I can't just do num = num or num? My second question:
So what do I need to do for the size method to work with the main method? Since it says that the return is outside of the method, also does Python cast automatically? Ken |
Author: | wtd [ Wed Nov 04, 2009 10:24 am ] |
Post subject: | RE:Methods Java to Python help? |
Have you read any Python tutorials? |
Author: | [Gandalf] [ Wed Nov 04, 2009 10:42 pm ] | ||
Post subject: | RE:Methods Java to Python help? | ||
Indeed, it seems like you're a Java coder who just picked up the Python library documentation and started piecing together code. I could be wrong. Anyway, you'll definitely want to look into a step-by-step guide on OOP in Python. Also, Python does not "cast automatically", take for instance:
Is foo a string or an integer? Is it neither? |
Author: | Kenster102.5 [ Thu Nov 05, 2009 11:04 am ] | ||
Post subject: | Re: RE:Methods Java to Python help? | ||
[quote="[Gandalf] @ Wed Nov 04, 2009 10:42 pm"]Indeed, it seems like you're a Java coder who just picked up the Python library documentation and started piecing together code. I could be wrong. Anyway, you'll definitely want to look into a step-by-step guide on OOP in Python. Also, Python does not "cast automatically", take for instance:
Is foo a string or an integer? Is it neither?[/quote] Well yes you are totally right, I am a Java Coder who just picked up Python, because it was introduced unofficially into my class cirriculum by another student in my class. So I feel that I should at least try to explore it. So what did I do wrong with calling my Size object? |
Author: | wtd [ Thu Nov 05, 2009 12:16 pm ] |
Post subject: | RE:Methods Java to Python help? |
Is "Size" perhaps meant to be a function? |
Author: | Kenster102.5 [ Thu Nov 05, 2009 5:58 pm ] |
Post subject: | Re: RE:Methods Java to Python help? |
wtd @ Thu Nov 05, 2009 12:16 pm wrote: Is "Size" perhaps meant to be a function?
Yes it is supposed to be a function, I just noticed that myself. Silly me. I will reply back tomorrow, since I am busy right now. |
Author: | Kenster102.5 [ Wed Nov 11, 2009 12:35 pm ] |
Post subject: | Re: Methods Java to Python help? |
I am sorry for not having such a quick reply, but now what should I do that would fit this scenario with the Size method. |