On 8/25/10, Andrew Martin <amartin7...@gmail.com> wrote: > All I want to do is add a line that displays that maximum height the > cannonball reaches. I created a variable zenith to store the highest y > value. I then wanted to compare the current y value of the cannonball to > zenith while the cannonballs y value is greater than zero. If the > cannonballs current y value is greater than zenith, I want to have the > current value replace zenith. Finally, once the cannonball has reaches y = > 0, I wanted the program to write out the value for zenith. > > I want to compare zenith, a floating point number, with the current y value? > I thought the current y value could be retrieved by Projectile.getY. And how It can, but you need parentheses after the function call. > do I call the getY using the instance? I think the problem may be where you say ball.getY instead of ball.getY() When you hear "instance", do not panic. An instance is just a variable of type class. For example, "ball" is an instance of the Projectile class. As an example, if I had a "pet" class, I might make a "dog" variable of type pet: dog=Pet() After I have my dog set up, since it is an instance of the Pet class, it has all the methods available in the Pet class. I might say dog.speak() which would just look at my Pet class for a "speak" method, and call it. In the same way, you have a "ball" variable which is a Projectile, so you have all the methods and variables from the Projectile class available in the "ball" variable. Note that, if a variable is of type class, it is also called an object, so I could have as easily called the "ball" a Projectile object. > > > > On Wed, Aug 25, 2010 at 7:24 PM, Alan Gauld > <alan.ga...@btinternet.com>wrote: > >> >> "Andrew Martin" <amartin7...@gmail.com> wrote >> >> >> However, when I did so I got this error: "TypeError: unbound method >> getY() >>> must be called with Projectile instance as first argument (got nothing >>> instead) " >>> >> >> def main(): >>>> angle, vel, h0, time = getInputs() >>>> cball = Projectile(angle, vel, h0) >>>> >>> >> cball is a Projectile instance >> >> >> zenith = 0.0 >>>> while cball.getY() >= 0: >>>> >>> >> So this is fine >> >> >> cball.update(time) >>>> >>> >> >> if Projectile.getY > zenith: >>>> zenith = Projectile.getY() >>>> >>> >> But what are you doing here? >> You are trying to compare the getY method of the class with a floating >> point number? >> Then you call getY using the class rather than the instance? >> I'm confused - and so is Python... >> >> >> -- >> Alan Gauld >> Author of the Learn to Program web site >> http://www.alan-g.me.uk/ >> >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >
-- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor