Using classes:


1) create a Python program class that will add two numbers and print the result

class add_method:
    def __init__(self, num01, num02):
        self.num1 = num01
        self.num2 = num02
        print(self.num1 +self. num2)
    

add_method(50,10)

--------------------------------------------------------------------------------------------------
2) create a Python program class that will add two numbers and return the result

class cal_methods:
    def add(self, num01, num02):
        self.num1 = num01
        self.num2 = num02
        return(self.num1 + self. num2)
    

function = cal_methods()
print(function.add(70,15))

--------------------------------------------------------------------------------------------------
3) Write Python program classes for a simple calculator that can perform
   addition, subtraction, division and multiplication.

   * hint user supplies two numbers and the program will ask what function to perform.

class cal_methods:
   #def __init__(self):
      #self.num01 = num1
      #self.num02 = num2
   
   def add(self, num1, num2):
     return num1 + num2

   def sub(self, num1, num2):
     return num1 - num2
   
   def multi(self, num1, num2):
     return num1 * num2
   
   def divi(self, num1, num2):
     return num1 / num2
    

function = cal_methods()


x = int(input("enter first number"))
y = int(input("enter second number"))

print("select function")
select = input("1) add two numbers\n2) subtract two numbers\n3) multiply two numbers\n4) divide two numbers\n")

if select == "1":
   print(x, " + ", y, "= ", function.add(x,y))
    
if select == "2":
   print(x, " - ", y, "= ", function.sub(x,y))
    
if select == "3":
   print(x, " * ", y, "= ", function.multi(x,y))
    
if select == "4":
   print(x, " / ", y, "= ", function.divi(x,y))



--------------------------------------------------------------------------------------------------
Dictionary:

4) create a Python program that uses a dictionary to store 
    an employees name, position, salary, and start date.

employee_dict ={
  "name": "Ford Tinkler",
  "position": "Sales",
  "salary": 60000,
  "startDate": "01/01/2018"
}

print(employee_dict)



--------------------------------------------------------------------------------------------------
5) create a Python program that uses a dictionary to store 
    an employees name, position, salary, and start date.
    * add a new field to the dictionary...
    * remove one of the other fields for the dictionary...

employee_dict ={
  "name": "Ford Tinkler",
  "position": "Sales",
  "salary": 60000,
  "startDate": "01/01/2018"
}

print(employee_dict)

# create temp dict. element.
temp = {"endDate": "01/01/2019"}
employee_dict.update(temp)
print(employee_dict)

# remove dict. element.
employee_dict.pop("salary")
print(employee_dict)
   

--------------------------------------------------------------------------------------------------
6) create a Python program class that will uses a dictionary to store 
    an employees name, position, salary, and start date.

class employee_methods:
    employee = {"name": "Ford Tinkler",
                "position": "Sales",
                "salary": 60000,
                "startDate": "01/01/2018"}

    def display(self):
      print(self.employee) 

    def update_name(self, inp_name):
      self.employee["name"] = inp_name 

    def update_pos(self, inp_pos):
      self.employee["position"] = inp_pos 

    def update_pay(self, inp_pay):
      self.employee["salary"] = inp_pay 

    def update_start(self, inp_start):
      self.employee["startDate"] = inp_start 


function = employee_methods()

function.display()

function.update_name("Victor Guerrido")
function.update_pos("Engineering")
function.update_pay("not nearly enough")
function.update_start("06/16/1991")


function.display()


--------------------------------------------------------------------------------------------------
imports:

7) create a Python program which imports your previous classes to perform the calulator.

* first create a python file with just a class inside...
#---------------------------------------------
class Cal_Methods:
   
   def add(self, num1, num2):
     return num1 + num2

   def sub(self, num1, num2):
     return num1 - num2
   
   def multi(self, num1, num2):
     return num1 * num2
   
   def divi(self, num1, num2):
     return num1 / num2

* And save this as "cal_class.py"

#----------------------------------------------
#
from cal_class import Cal_Methods

function = Cal_Methods()


x = int(input("enter first number"))
y = int(input("enter second number"))

print("select function")
select = input("1) add two numbers\n2) subtract two numbers\n3) multiply two numbers\n4) divide two numbers\n")

if select == "1":
   print(x, " + ", y, "= ", function.add(x,y))
    
if select == "2":
   print(x, " - ", y, "= ", function.sub(x,y))
    
if select == "3":
   print(x, " * ", y, "= ", function.multi(x,y))
    
if select == "4":
   print(x, " / ", y, "= ", function.divi(x,y))


--------------------------------------------------------------------------------------------------
8) create a Python program which imports your previous classes to manage your employee.

* first create a python file with just a class inside...
#---------------------------------------------
class employee_methods:
    employee = {"name": "Ford Tinkler",
                "position": "Sales",
                "salary": 60000,
                "startDate": "01/01/2018"}

    def display(self):
      print(self.employee) 

    def update_name(self, inp_name):
      self.employee["name"] = inp_name 

    def update_pos(self, inp_pos):
      self.employee["position"] = inp_pos 

    def update_pay(self, inp_pay):
      self.employee["salary"] = inp_pay 

    def update_start(self, inp_start):
      self.employee["startDate"] = inp_start 

    def get_salary(self):
      return(self.employee["salary"]) 


* And save this as "employ_class.py"

#----------------------------------------------
#
from employ_class import employee_methods

function = employee_methods()

function.display()

function.update_name("Victor Guerrido")
function.update_pos("Engineering")
function.update_pay("not nearly enough")
function.update_start("06/16/1991")


function.display()


--------------------------------------------------------------------------------------------------
9) create a Python program which imports your previous classes "calculator & employee"
   to calulate raises and paycuts for the employee.

#
from employ_class import employee_methods
from cal_class import Cal_Methods

pay_cal = Cal_Methods()
emp_data = employee_methods()

emp_data.display()

current_pay = emp_data.get_salary()
print("current salary is $", current_pay, "\n")

x_raise = 10000
new_pay = pay_cal.add(current_pay, x_raise)
emp_data.update_pay(new_pay)

emp_data.display()

current_pay = emp_data.get_salary()
print("updated salary is $", current_pay, "\n")

x_cut = 15000
new_pay = pay_cal.sub(current_pay, x_cut)
emp_data.update_pay(new_pay)

emp_data.display()

current_pay = emp_data.get_salary()
print("updated salary is $", current_pay, "\n")

 
