What is a return value?

A return value is the value that is returned when a function or a method is called.

That return value can be assigned or printed

What is a Procedure?

What Are Functions?

What Are The Components of a Function?

# College Board Pseudo code
# Calling Procedures:
procName(arg1, arg2,...)

# Defining Procedures
procedure procName (parameter1, parameter2, ...){
    <block of statements>
    RETURN expression
}


# Defining Functions in python
#
# def function_name(parameter1, parameter2, etc..):
#     code here...
#
#     return return_value;

# return the value of parameter1 plus parameter2;
def add(parameter1, parameter2): # creates a function that takes in two parameters
    solution = parameter1 + parameter2; # sets solution to the sum of parameter1 and parameter2
    return solution; # return solution
    
print(add(5, 5)); # prints the return value of subtract(5,5)

Popcorn Hack 1:

1. Make a function that returns the difference of two numbers

2. The function should pass two user input variables as the arguments

3. CHALLENGE: Copy and paste the add function from above and make the difference method return the sum of the return value of the add function and the return value of the difference function.

# Code Here

What is a Class?

How Does a Class Work?

# Defining Classes
class person:
    def __init__(self, name, age, ): # constructor
        self.name = name; # instance variable
        self.age = age; #instance variable
    
    def getName(self): # method to create get name
        return self.name;
    
    def getAge(self): # method to create get age
        return self.age;
    
    def setName(self, name): # method to create set name
        self.name = name;
        
    def setAge(self, age): # method to create set age
        self.age = age;
        
    def yearOlder(self): # method to increment age by 1
        self.age += 1;
        
    def __str__(self): # method that returns a string when the object is printed
        return (f"My name is {self.name} and I am {self.age} years old.")

Person1 = person("John Doe", 15);
print(Person1)


print(Person1);

Popcorn Hack 2:

Create a constructor of a pet class that has three instance variables. - name, age, type

Popcorn Hack 3:

1. Create a Car class which has the attributes model, vehicle name, and price

2. Create a getter method for each of the attributes

3. Create instances of the following cars

4. Print the Name of each instance

Homework:

Assignment 1: How do you use functions?

Create a turtle python function that...

  1. Takes a single parameter as the number of sides
  2. Outputs a shape corresponding to the number of sides
  3. Call the function with the argument being a variable with the user input

Hint:

import turtle

pen = turtle.Turtle(); # pen is the instance of Turtle which has methods that do certain actions

# Necessary methods:
# .forward(50) - moves the pen forward 50 units
# .right(angle) - turns the pen angle degrees right   
# OR
# .left(angle) - turns the pen angle degrees left

def shape(sides):
    # code here...
    # set each side to be 50 units long
    # The interior angle of each angle is equal to ((sides-2)*180)/sides

# ask user for sides and pass as argument for the function

Assignment 2:

Create a student class that...

  1. Has a constructor that takes three parameters as attributes
    • email
    • name
    • grade
  2. Three getter methods to access the name, email, and grade
  3. Three setter methods to modify the name, email, and grade
  4. A to string method that returns the three instance variables in this format - "My name is {name}. My email is {email}. My grade is {grade}
  5. Create an instance of the class that corresponds with you
class student:
    def __init__(self, parameters...):
        #code here...
        pass; #don't include
    
    def getName(self): # method to create get name
        #code here...
        pass; #don't include
    
    def getGrade(self): # method to create get grade
        #code here...
        pass; #don't include
    
    def getEmail(self): # method to create get email
        #code here...
        pass; #don't include
    
    def setName(self, name): # method to set name
        #code here...
        pass; #don't include
        
    def setAge(self, age): # method to set age
        #code here...
        pass; #don't include
        
    def setEmail(self, email): # method to set email 
        #code here...
        pass; #don't include
        
    def __str__(self): # method that returns a string when the object is printed
        #code here...
        pass; #don't include
        #format :"My name is {name}. My email is {email}. My grade is {grade}"
    
#create an instance of the class corresponding to you then print the instance using: print(object)