[Tutor] I am having trouble getting some associations to work

Alan Gauld alan.gauld at yahoo.co.uk
Sun Feb 27 19:57:22 EST 2022


On 27/02/2022 20:09, Tom Linsenmeyer wrote:
> I cannot get either self or getmakecar and getmaketruck to associate with
> self or def getmakecar() and getmaketruck(). 

I don't really understand what you mean by that.
In what way does self not associate with self?

I do note that you are trying to call methods of
the class from inside other methods but not prefixing
them with self.

Is that what you mean? For example...

>   def mainmenu(self):
> 
>           print("Welcome to your garage! Please make a selection")
>           print("1: Car")
>           print("2: Truck")
>           print("3: Quit")
>           choice = int(input())
>           if choice == 1:
>             print("Car")
>             getmaker()
>           #elif choice == 2:
>            # getmakeTruck()

Should be

self.getmakeTruck()

Also, you don't seem to have a method or function called getmaker()?

Although, from an OOD point of view those are terrible methods
to have in a Vehicle class! There should be Vehicle sublasses
for both car and truck... But those are design choices.
You seem to be asking about code.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list