class Company(object): # Class Open """Company object Programmatically defines what and/or who a company is, their hiring status, and whether they have remote opportunities (Protected) Attributes: _id: company index id | integer _name: company name | string _hiring: is company hiring | boolean _employees_can_work_remote: is the workforce local only | boolean """ # protected|int _id = 0 # protected|string _name = '' # protected|bool _hiring = False # protected|bool _employees_can_work_remote = False def __init__(self): """Class Constructor""" pass def get_id(self): """Gets the integer value of _id Returns: _id: int|internal value of _id property """ return self._id def set_id(self, value): """Sets integer value of _id Args: value: integer|value of property _id Returns: self (object) Raises: ValueError: exception when value sent of the wrong Value-Type -- e.g. int expected, string supplied """ try: self._id = int(value) return self except ValueError: print("Could not convert data to an string.") except: print("Unexpected error:", sys.exc_info()[0]) raise def get_name(self): """Gets the string value of _name Returns: _name: string|internal value of _name property """ return self._name def set_name(self, value): """Sets value of _name Args: value: integer|value of property _name Returns: self (object) Raises: ValueError: exception when value sent of the wrong Value-Type -- e.g. int expected, string supplied """ try: self._name = str(value) return self except ValueError: print("Could not convert data to an string.") except: print("Unexpected error:", sys.exc_info()[0]) raise def get_hiring(self): """Gets the boolean value of _hiring Returns: _hiring: boolean|internal value of _hiring property """ return self._hiring def set_hiring(self, value): """Sets boolean value of _hiring Args: value: boolean|value of property _hiring Returns: self (object) Raises: ValueError: exception when value sent of the wrong Value-Type -- e.g. int expected, string supplied """ try: self._hiring = bool(value) return self except ValueError: print("Could not convert data to an boolean.") except: print("Unexpected error:", sys.exc_info()[0]) raise def get_employees_can_work_remote(self): """Gets the boolean value of _employees_can_work_remote Returns: _employees_can_work_remote: boolean|internal value of _employees_can_work_remote property """ return self._employees_can_work_remote def set_employees_can_work_remote(self, value): """Sets boolean value of _employees_can_work_remote Args: value: boolean|value of property _employees_can_work_remote Returns: self (object) Raises: ValueError: exception when value sent of the wrong Value-Type -- e.g. int expected, string supplied """ try: self._employees_can_work_remote = bool(value) return self except ValueError: print("Could not convert data to an boolean.") except: print("Unexpected error:", sys.exc_info()[0]) raise # Class Close def var_to_bool(value): # Function Open """Converts input value to boolean. Possible 'True' values: 1, True, "1", "TRue", "yes", "y", "t" Possible 'False' values: 0, False, None, [], {}, "", "0", "faLse", "no", "n", "f", 0.0, ... Args: value: int|string|array|object -- value to try to convert to boolean Raises: exception for invalid formats """ if str(value).lower() in ("yes", "y", "true", "t", "1"): return True else: return False raise Exception('Invalid value for boolean conversion: ' + str(value)) # Function Close apply_for_job = { "remote_yes":"I can haz job!? (read: APPLY IMMEDIATELY!!)", "remote_no":"Maybe next time..." } company = Company() company.set_id(1) company.set_name('Hammer and Chisel (Discord)') company.set_hiring(True) company.set_employees_can_work_remote(var_to_bool((raw_input("Can employees work remote (telecommute)? (y/n): \n")).lower())) print "Company Name: " + str(company.get_name()) print "Company is Hiring: " + str(company.get_hiring()) print "Employees can work from home/out of state/remote: " + str(company.get_employees_can_work_remote()) if(company.get_employees_can_work_remote()): print "\nApply for this job: " + apply_for_job["remote_yes"] else: print "\nApply for this job: " + apply_for_job["remote_no"]
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question