This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, pygame | |
pygame.init() | |
size = width, height = 600, 600 | |
speed = [1, 1] | |
red = 130, 202, 154 | |
screen = pygame.display.set_mode(size) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# Code Em Level 2 - Icebreaker | |
# a program to generate random numbers by using the random module | |
# a random number is picked, and the user must guess the number between 1 and 100. | |
import random | |
number = random.randint(1, 100) | |
print("I'm thinking of number between 1 and 100") | |
print("Try to guess the number with as few attempts as possible") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# CREATING AND USING A CLASS | |
# You can model model almost anything using classes. | |
# Let's start by defining classes from our first example. | |
class Things(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# CREATING AND USING A CLASS | |
# You can model almost anything using classes. Let's start by writing a simple | |
# class, Computer, that represents a modern computer --not one computer in particular, but any modern computer. | |
# What do we know about most modern computers? | |
# They have a name and can store memory. | |
# and many computers can take input and display input. | |
# The two pieces of information (name and memory capacity) | |
# and the two behaviors (input and output) can go in the class Computer, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's get some input from the user. | |
name = raw_input('Please enter your name: ') | |
# How can we do something with the value that was entered? | |
# In other words, how can we display the user's name??? | |
# one way, is a print statement with some concatenation (or adding strings and variables nad other characters) | |
print("Hello " + name + "!") | |
#### | |
#### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# example code from Crash Course Python by Eric Matthes | |
# Recall for loops | |
# The for loop takes a collection of items and executes a block of code once | |
# for each item in the collection. | |
# PYTHON WHILE LOOPS | |
# In contrast, the while loop runs as longs as (or while) a certain condition is true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# In this example, the user's will be asked for their name and a stream or river they visited | |
# setting up empty dictionary | |
responses = {} | |
# Set a flag to indicate that polling is active. | |
polling_active = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# The following example is a rendition from Python Crash Course by Eric Matthes | |
# The transect example is inspired by my experience in field biology | |
# Remember, if we want to remove an item from a list, we use the remove() function. | |
# This worked, because the value we wanted to remove only appeared once in the list. | |
# Let's say you had a list of different kinds of trees with the value 'red maple' | |
# repeated several times. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Any line that starts with a pound sign (#) is known as a comment, Python knows to ignore comments | |
# Comments are useful for explaining what you are doing in a program to yourself or someone else who might be working on the same program | |
# Let's write a calculator program that has the computer ask the user for two number to calculate, then return the answer | |
# to have a program accept input from a user, we use the raw_input() function, Python automatically considers what the user types in as a string. | |
print("Please give me a number") | |
number1 = raw_input() # here's our first variable | |
print("Please give me another number") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.7 | |
# code examples and explanations from Python Crash Course by Eric Matthes | |
#### | |
#### | |
# echo.py | |
# A simple program to have the computer take input from the user... Or so it seems! |