Newton Girls Who Code
Tuesday Session 8, 12-11-2018
Welcome!
Plan for Today
Function review
What is a function?
# Let's define a function.�def function_name(argument_1, argument_2):� # Do whatever we want this function to do,� # using argument_1 and argument_2��# Use function_name to call the function.�function_name(value_1, value_2)
Reviewing Functions
Begin by opening: https://www.python.org/shell/
Beginner: Write out a function that prints “Hi, my name is Ann” when you call the function name(Ann)
Intermediate: Write out a function that sums two numbers, so when you call sum_num(3,4) you get 7
Challenge: Write a function to determine if a number is prime. Should print “True” if prime and “False” if not (ex, is_prime(5) should return True)
Spotlight: Women Who Code
Arlene Garcia-Gunderson
Watch Video�
What is an Object?
Student
traits
- hair color
- age
Can do
- codes
- plays Violin
class Student
�Methods or functions
- codes(language)
- playsViolin()
How to use objects in Python
class Student:
def __init__(self, name, age): //self - reference to the class
self.name = name
self.age = age
def code(language):
print("I code in " + language)
student = Student("Mary", 15)
//call method
student.code(“python”); // ----will print: I code in python
print(student.name)
print(student.age)
Python Syntax
Exercises:
https://www.w3schools.com/python/exercise.asp?filename=exercise_operators1
Resources:
https://www.tutorialspoint.com/python/python_basic_operators.htm�
Classes
https://www.w3schools.com/python/python_classes.asp
Interactive
https://www.learnpython.org/en/Classes_and_Objects
Continue working on your projects!
Plan for Today
Stand-up
Start with your name, then choose from the following questions:
If you have an idea for next week’s lightning standup,
e-mail instructors@newtongwc.org and let us know
See you next week!