Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with class inheritance - Python
    text
    copied!<p>I'm fairly new to python and was having trouble with an inheritance classes. This is for an online introduction to computer programming class and I do not have the resources to figure out where I went wrong with my code. Here is the code:</p> <pre><code>class Employee: def __init__(self, employeeName, employeeShift): self.__name = employeeName self.__number = employeeShift def set_name(self, nam): self.__name = nam def set__number(self, num): self.__number = num # Accessor methods def get_name(self): return self.__name def get_number(self): return self.__number # ProductionWorker class that inherited the Employee class class ProductionWorker(Employee): def __init__(self, shift, payRate): self.__shift_number = shift self.__pay_rate = payRate def set_shift_number(self, shift): self.__shift_number = shift def set_pay_rate(self, pay): self.__pay_rate = pay # Accessor methods def get_shift(self): return self.__shift def get_shift(self): if self.__shift_number = '1': s = 'Day shift' else self.__shift_number = '2': s = 'Night shift' return s def get_pay(self): return self.__pay def get_pay(self): if self.__pay_rate &lt;= 5: p = 7.50 elif self.__pay_rate &gt; 5 and self.__pay_rate &lt;= 15: p = 13.50 else self.__pay_rate &gt;= 20: p = 20 return p # main module def main(): # Prompts the user for employee name, shift and pay rate employeeName = raw_input("Please enter the employee name: ") print "Please enter which shift the employee works." employeeShift = input("1 for day shift, 2 for night shift: ") payRate = input("How long has the employee worked here? ") # Creates object of ProductionWorker worker = ProductionWorker(employeeName, employeeShift, payRate) # Displays information print "Employee name:", worker.get_name() print "Employee shift:", worker.get_shift() print "Employee pay rate:", worker.get_pay_rate() # calls main module main() </code></pre> <p>It tells me that there is a syntax error in the <code>ProductionWorker</code> class, under the <code>def get_shift()</code> where I have the <code>self.__shift_number = '1'</code>. I followed my professor's example, so I don't really understand this error.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload