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 random | |
number = random.randint(1, 100) | |
print number | |
GameRunning = True | |
while True: | |
guess = int(raw_input("Guess a number between 1-100: ")) | |
if guess == number: | |
GameRunning = True | |
print("You guessed correctly!") | |
elif guess > 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
# A simple program to demonstrate using a for loop | |
# To print hello world! five times in Python, you could type | |
# print('hello world!') five times, each on its own line | |
# Or, you could use a 'for loop' to have the same result with less typing: | |
for x in range (0, 5): | |
print('hello world!') | |
# The range function can create a list of numbers ranging from a starting number | |
# to the number just before the ending 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
# BASIC SNAKE GAME | |
# python 2.7 | |
import pygame | |
import time | |
import random | |
pygame.init() | |
black = (0, 0, 0) | |
white = (255, 255, 255) |
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 random # importing the random module | |
number = random.randint(1, 100) # were are creating a variable to equal an array (or range) of numbers for the computer to choose from | |
GameRunning = True | |
while True: # make a loop | |
guess = # don't forget your indents | |
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 turtle | |
t = turtle.Turtle() | |
print("Give me a number") | |
number1 = raw_input() | |
print("Give me another number") | |
number2 = raw_input() | |
number1 = int(number1) |
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
# BASIC SNAKE GAME | |
import pygame | |
import time | |
import random | |
pygame.init() | |
black = (0, 0, 0) | |
white = (255, 255, 255) | |
red = (255, 0, 0) |
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 random | |
number = random.randint(1, 100) # Here's the range of numbers the computer randomly chooses from | |
print number # this line is just so you can test/see the numbers the computer chooses from | |
# You likely want to comment this out once your whole program is running! | |
# GameRunning variable here | |
# Start your while loop here, Watch your indents below this loop! | |
guess = int(raw_input("Guess a number between 1-100: ")) # letting Python know this is an integer | |
if guess == number: # starting your condition statements |
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
from dictionary import * # importing another program so we can use its code in this new program | |
# START WITH AN EMPTY LIST | |
classmates = [] | |
# USING THE APPEND FUNCTION TO ADD DICTIONARIES TO THE EMPTY LIST | |
classmates.append(john) | |
classmates.append(jane) | |
classmates.append(sue, james, bart) # adding multiple dictionaries at one time |
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 | |
# Objectives: modules, game surface, Frames/sec (FPS), "skeleton" of a game, game loop, color, | |
# setting object size, random, lists | |
# Rather than typing from scratch (only ~50min of lecture available), students will | |
# each have these lines of code for a basic snake game using pygame. | |
# Lines will either be omitted or commented out | |
# students will follow along via the instructor/whiteboard; either typing in a few lines of code where its needed | |
# and/or students will uncomment lines of code that carry out specific feature related to the objectives |
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 | |
# By Joe | |
# Below is a basic review of dictionaries in Python | |
# starting with an empty dictionary, then adding information to it | |
# Example: | |
# MAKE AN EMPTY DICTIONARY | |
john = {} | |
# ADDING KEY-VALUE PAIRS TO THE DICTIONARY |