@ Girls in STEM: Board Co-Chair
@ ViaSat Inc.: Business Systems Analyst
also: ViaSat STEAM Program Champion, Women in
Technology board member
@ Girls in STEM: Middle School Program + Website
@ mmmanyfold: Co-Founder + Full-Stack Developer
@ KidsTek: Teaches "Intro to Programming" elective at Hinkley High School
resize the windows so this can be right next to the slides
this is a code block
code block
...can be thought of as containers that hold information (data).
Their sole purpose is to label and store data in computer memory.
This data can then be used and changed throughout your program.
x = 0
x = x + 1
x = x + 1
x = x + 1
Q1: What will be the final value of x?
x = 0
x = x + 1
x = x + 1
x = x + 1
print(x)
A: add this print() function at the end & then run it to see if you're right
name = "Wendy"
name = name + " Merchant"
name = name + ", P.E."
Q2: What will be the final value of name?
name = "Wendy"
name = name + " Merchant"
name = name + ", P.E."
print(name)
A: add this print() function & then run it to see if you're right
Types of values include:
String "Wendy"
Integer (whole #) -4
Float (decimal #) 5.01248
Array (list) ["Wendy", -4, 5.01248]
Boolean True or False
...is a piece of data that goes in to a program.
The program does something with it, and often (but not always) spits out an...
ascii art generator
cat.jpg
text
ascii art generator
RGB sensors (cones) in the human eye - we have a few million of these, which are equivalent to megapixels
artificial intelligence: "computer vision"
photobooth effects
SNAPCHAT!!!
strings, integers, and variables are like nouns. they just exist.
a function is a verb. it does things!
Let's define a simple greeting function:
def greet(name):
print("Hi " + name)
name of
our function
in parentheses, we name our "arguments" - any input values our function will need in order to run
everything after the first line is what the function will do, when it's "called"
def greet(name):
print("Hi " + name)
this part "calls" the function, telling it to actually execute
def greet(name):
print("Hi " + name)
greet("Shelly")
BTW, print() is also a function - it comes built in with Python :)
def greet(name):
print("Hi " + name)
scale_image(image, new_width=100) # resizes an image convert_to_grayscale(image) # converts image to grayscale map_pixels_to_ascii_chars(image, range_width=25) # maps each pixel to a character based on its number range. 0-255 is divided into 11 ranges of 25 pixels each convert_image_to_ascii(image, new_width=100)
# calls all of the functions above in a specific order, resulting in a string of characters handle_image_conversion(image_filepath) # calls convert_image_to_ascii (above) on the image file provided
#!/usr/bin/env python
# this script converts an image to ascii art
# adapted from https://www.hackerearth.com/practice/notes/beautiful-python-a-simple-ascii-art-generator-from-images/
# must have PIL or Pillow installed
from PIL import Image
ASCII_CHARS = [ '#', '?', '%', '.', 'S', '+', '.', '*', ':', ',', '@']
def scale_image(image, new_width=100):
# resizes an image, slightly adjusting the aspect ratio.
(original_width, original_height) = image.size
aspect_ratio = (original_height/float(original_width)) * .5
new_height = int(aspect_ratio * new_width)
new_image = image.resize((new_width, new_height))
return new_image
def convert_to_grayscale(image):
return image.convert('L')
def map_pixels_to_ascii_chars(image, range_width=25):
# maps each pixel to an ascii char based on the range in which it lies.
# 0-255 is divided into 11 ranges of 25 pixels each.
pixels_in_image = list(image.getdata())
pixels_to_chars = [ASCII_CHARS[pixel_value//range_width] for pixel_value in
pixels_in_image]
return "".join(pixels_to_chars)
def convert_image_to_ascii(image, new_width=100):
image = scale_image(image)
image = convert_to_grayscale(image)
pixels_to_chars = map_pixels_to_ascii_chars(image)
len_pixels_to_chars = len(pixels_to_chars)
image_ascii = [pixels_to_chars[index: index + new_width] for index in
range(0, len_pixels_to_chars, new_width)]
return "\n".join(image_ascii)
def handle_image_conversion(image_filepath):
image = None
try:
image = Image.open(image_filepath)
except Exception as e:
print("Unable to open image file {image_filepath}.".format(image_filepath=image_filepath))
print(e)
return
image_ascii = convert_image_to_ascii(image)
print(image_ascii)
if __name__=='__main__':
import sys
image_file_path = "karen.jpg"
handle_image_conversion(image_file_path)
while 0 == 0:
choice = input("\nReply 1 if you'd like to learn more about 'if statements'. Reply 2 if you'd rather not.\n")
if (choice == "1"):
print("\nAn 'if statement' takes a certain test (in this case: is 'choice' equal to 1?) and acts based on the 'truthiness' of that test. Truthiness is a funny word that basically refers to a Boolean - a binary variable, having two possible values: 'true' or 'false'. It's named after the mathematician George Boole. Thanks to 'if statements' and Booleans, our code can have many alternate universes...")
elif (choice == "2"):
print("\nMeow")
elif (choice == "hi"):
print("\nwell hello there")
else:
print("\nNot a valid response!")
SHORTCUT:
select everything
+ press tab
(to indent all
at once)
1) Front-End Developer develops the part of an application that the user can see and interact with (html/css, javascript) 2) Back-End Developer develops the part of an application that handles logic, database interactions, user authentication, server config. (sql, python)
3) Full-Stack Developer a front-end and back-end developer who codes in multiple languages and understands how application servers communicate (http, REST) 4) Data Scientist / Engineer analyzes data, finds patterns, illustrates with pics (statistics) 5) UX Designer makes apps easy for people to use (graphics, layouts, clicks)