Python Forum
Help for my assignment - Object Oriented Programming
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help for my assignment - Object Oriented Programming
#2
To define a class and subclasses, use the class keyword:

class Vending_Machine:
    def __init__(self): # init constructs the class at instantiation
        pass

def Balance(Vending_Machine):
    def __init__(self):
        pass
As for organizing your code, methods can be defined by defining a function indented under the definition of the class (as above). In Python, there is no distinction of public or private when it comes to methods and attributes. The convention is to use a leading underscore for private methods and attributes, but it does nothing in the interpretter.

For your code, I would make the items in items() into attributes under Vending_Machine. They would also be a pair of dicts instead of a trio of lists. By the way, lines 11 through 27 on items() don't really do anything.

Now, subclasses need to make sense in relation to their superclass. Vending_Machine being the superclass of Balance, Items, and Keypad doesn't make sense (e.g. a Keypad is not a vending machine in real life). For what you have, Vending_Machine, Keypad, and Item make sense and the last two make sense as objects stored inside Vending_Machine, not as subclasses though.

Try reorganizing your code under a few classes and we can provide more advice.
Reply


Messages In This Thread
RE: Help for my assignment - Object Oriented Programming - by stullis - Jan-05-2019, 02:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with writing an objective oriented python assignment mikikiki 5 2,108 Feb-21-2023, 01:18 PM
Last Post: jefsummers
  Verilog HDL Programming to Python Programming? noobcoder 1 3,079 Jul-18-2019, 09:28 PM
Last Post: nilamo
  Object oriented area of a triangle xterakojede 2 8,997 Apr-20-2018, 01:42 PM
Last Post: xterakojede
  Unit 18: Procedural Programming Assignment (Shop Simulation) shaheduk323 28 13,720 Dec-17-2017, 08:31 PM
Last Post: Terafy
  programming assignment mario 2 3,523 Dec-16-2017, 06:28 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020