From 42d6c4c1486be80b82a32949db644a8eec9adddf Mon Sep 17 00:00:00 2001 From: micaKohl Date: Mon, 26 Oct 2015 03:52:18 -0500 Subject: [PATCH 1/5] Created Scope.py for Scope Lesson (Lesson 2) --- .idea/workspace.xml | 121 +++++++++++++++++++++++++++++--------------- Constants.py | 2 +- Scope.py | 48 ++++++++++++++++++ checklist1.txt | 28 ---------- 4 files changed, 129 insertions(+), 70 deletions(-) create mode 100644 Scope.py delete mode 100644 checklist1.txt diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5c6473b..bd8d16c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,7 @@ - - - - - + + + + @@ -80,6 +85,8 @@ @@ -87,10 +94,10 @@ - @@ -115,7 +122,6 @@ - @@ -136,14 +142,17 @@ + - + + + @@ -303,27 +312,27 @@ - + - + - - + + @@ -364,6 +373,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -508,39 +545,41 @@ - - + + - - - - - - - - - - + + - + - - + + + + + + + + + + + + \ No newline at end of file diff --git a/Constants.py b/Constants.py index e304249..718810f 100644 --- a/Constants.py +++ b/Constants.py @@ -11,4 +11,4 @@ blockSize = 20 # The maximum number of blocks on each side. xBound = 30 -yBound = 30 +yBound = 30 \ No newline at end of file diff --git a/Scope.py b/Scope.py new file mode 100644 index 0000000..f75349c --- /dev/null +++ b/Scope.py @@ -0,0 +1,48 @@ +import pygame, sys +from random import randint + +# This file is where we're going to learn about scope, before we start digging around in the main game +# Here is a great place to make changes and experiment + +# Part 1: Global Variables +# Q 1.1: What happens if we get rid of the global keyword? Will that happen no matter where we use global? +global scores + +# Part 2: Variables in Loops +for i in range(0,20): + scores[i] = randint + +# Q 2.1: We're outside of our loop. What happens if we print i? + +# Part 3: Variables in functions +def check_high_score(oldScore, newScore): + #Q 3.1: We're inside our function. What value does newScore have? + if oldScore < newScore: + return newScore + else: + return oldScore +# Q 3.2: We're outside of our function. What value does newScore have? + +# Part 4: Variables in Classes +class Player(object): + # This is how we create an object in Python + def __init__(self, name): + # declare and initialize an instance variable + # Q 4.1 We use self in Python like we use this in Java. Something very different about the two. What? + self.name = name + self.score = 0 + + # Q 4.2: Can we use the same name "newScore" from Part 3 here? Why or why not? + def new_score(self, newScore): + self.score = check_high_score(self.score, newScore) + +# Q 4.3: Why do we only have one parameter here, our function had two? What's going on? +exampleUser = Player("Mr. Chuah") +exampleUser.score = new_score(999999999999) +print exampleUser.name, exampleUser.score + +# Part 5: Show what you've got +# Q 5.1: Make two new players, name them after you and your partner. + +# Q 5.2: Give the players new highscores from our list # + diff --git a/checklist1.txt b/checklist1.txt deleted file mode 100644 index 02484dc..0000000 --- a/checklist1.txt +++ /dev/null @@ -1,28 +0,0 @@ --------------------------------------- -- Python Lesson 2: FUNctions & Color - --------------------------------------- - -Due to the changing seasons and shedding skin, the world of Snake looks greyer than it used to. -Your mission is to figure out how to change colors in our game and to change this boring, grey -world into something awesome. - -As you experiment with colors, make sure to answer the questions in this file. - -1) What does an RGB triple with low values like (20, 20, 20) look like? What about a triple with high values - like (240, 240, 240)? - -2) As you experiment with changing the color of the snake, keep track of the RGB values - that you discovered below. There are some colors that you should try to discover. - There are many ways to represent a color (for example, there are many shades of orange), - so record at least one RGB value. If you discover some cool colors, add them below! --- Example: GREY: (60, 60, 60) - -RED: -GREEN: -BLUE: -YELLOW: -PURPLE: -CYAN: - -3) How can we change the color of a block that already exists (like pieces of the snake)? - List how you modify the color of an existing block. From a6ce733346dace692a0e54dcf5b7d2572e8e4348 Mon Sep 17 00:00:00 2001 From: micaKohl Date: Mon, 26 Oct 2015 04:17:01 -0500 Subject: [PATCH 2/5] Un-numbered questions --- .idea/workspace.xml | 76 +++++++++++++++++++++++++++++---------------- Scope.py | 21 ++++++------- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bd8d16c..d258ed4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -36,8 +36,8 @@ - - + + @@ -58,8 +58,8 @@ - - + + @@ -94,10 +94,9 @@ - @@ -151,10 +150,27 @@ - + - + + + - + + + + + + + @@ -312,27 +334,27 @@ - + - + + + - - @@ -553,16 +575,6 @@ - - - - - - - - - - @@ -571,10 +583,20 @@ + + + + + + + + + + - - + + diff --git a/Scope.py b/Scope.py index f75349c..d3a54b0 100644 --- a/Scope.py +++ b/Scope.py @@ -3,46 +3,45 @@ # This file is where we're going to learn about scope, before we start digging around in the main game # Here is a great place to make changes and experiment +# Look for questions marked "Q" -- these will be asked in discussion # Part 1: Global Variables -# Q 1.1: What happens if we get rid of the global keyword? Will that happen no matter where we use global? +# Q: What happens if we get rid of the global keyword? Will that happen no matter where we use global? global scores # Part 2: Variables in Loops for i in range(0,20): scores[i] = randint -# Q 2.1: We're outside of our loop. What happens if we print i? +# Q: We're outside of our loop. What happens if we print i? # Part 3: Variables in functions def check_high_score(oldScore, newScore): - #Q 3.1: We're inside our function. What value does newScore have? + #Q: We're inside our function. What value does newScore have? if oldScore < newScore: return newScore else: return oldScore -# Q 3.2: We're outside of our function. What value does newScore have? +# Q: We're outside of our function. What value does newScore have? # Part 4: Variables in Classes class Player(object): - # This is how we create an object in Python + # This is how we create an object in Python. Notice the parameters def __init__(self, name): # declare and initialize an instance variable - # Q 4.1 We use self in Python like we use this in Java. Something very different about the two. What? + # Q: We use self in Python like we use this in Java. Something very different about the two. What? self.name = name self.score = 0 - # Q 4.2: Can we use the same name "newScore" from Part 3 here? Why or why not? + # Q: Can we use the same name "newScore" from Part 3 here? Why or why not? def new_score(self, newScore): self.score = check_high_score(self.score, newScore) -# Q 4.3: Why do we only have one parameter here, our function had two? What's going on? +# Q: Why do we only have one parameter here, our function had two? What's going on? exampleUser = Player("Mr. Chuah") exampleUser.score = new_score(999999999999) print exampleUser.name, exampleUser.score # Part 5: Show what you've got -# Q 5.1: Make two new players, name them after you and your partner. - -# Q 5.2: Give the players new highscores from our list # +# Make two new players, name them after you and your partner. Then, give the players new highscores from our list From ec1f8a3b1abf366abd87e105a4ae9884c9d20f5d Mon Sep 17 00:00:00 2001 From: micaKohl Date: Mon, 26 Oct 2015 05:16:25 -0500 Subject: [PATCH 3/5] Added Questions --- .idea/workspace.xml | 8 ++++---- Scope.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d258ed4..0a2fb68 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -36,8 +36,8 @@ - - + + @@ -595,8 +595,8 @@ - - + + diff --git a/Scope.py b/Scope.py index d3a54b0..ad7ab31 100644 --- a/Scope.py +++ b/Scope.py @@ -42,6 +42,20 @@ def new_score(self, newScore): exampleUser.score = new_score(999999999999) print exampleUser.name, exampleUser.score -# Part 5: Show what you've got -# Make two new players, name them after you and your partner. Then, give the players new highscores from our list +# Part 5: Show what you've got +# Make two new players, name them after you and your partner. +# Then, give the players new highscores from our list + +# Using a loop, add points to each player's score. + +# Find how much each player's score increased by. + +# Find which player has the lowest score. + +# Finally, describe the scopes of every variable you use. You must have at least four different scopes. + + + +# When you're done, brainstorm ideas with your partner about taking advantage of what we know about +# scope to add to our snake game. From 6d3e34b32641c291b36dab861326f6a291da8854 Mon Sep 17 00:00:00 2001 From: micaKohl Date: Mon, 26 Oct 2015 10:46:09 -0500 Subject: [PATCH 4/5] Created Scope Assessment Code --- .idea/workspace.xml | 43 +++++++++++++++++++++++++++++++------------ ScopeAssessment.py | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 ScopeAssessment.py diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0a2fb68..15db2a9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -33,11 +33,11 @@ - + - - + + @@ -45,6 +45,16 @@ + + + + + + + + + + @@ -87,6 +97,7 @@ @@ -575,6 +586,16 @@ + + + + + + + + + + @@ -583,23 +604,21 @@ - + - - + + - + - - - - - + + + diff --git a/ScopeAssessment.py b/ScopeAssessment.py new file mode 100644 index 0000000..dfc5a33 --- /dev/null +++ b/ScopeAssessment.py @@ -0,0 +1,25 @@ +__author__ = 'Mica' + +rainbowColors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"] +for i in range (7): + print rainbowColors[i] + +def foo(x): + x = x + global y + y = x * x + +for i in range (7): + print i + foo(i) + for j in range (i): + print '***' + print y + +class IceCream(object): + def __init__(self, flavor): + self.flavor = flavor + +favoriteFlavor = "chocolate" +scoop1 = IceCream("vanilla") +scoop2 = IceCream(favoriteFlavor) \ No newline at end of file From bb1ef4833c3e66633429acd8175c82bd5f7ae27d Mon Sep 17 00:00:00 2001 From: micaKohl Date: Mon, 26 Oct 2015 10:48:17 -0500 Subject: [PATCH 5/5] Added instructions --- .idea/workspace.xml | 8 ++++---- ScopeAssessment.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 15db2a9..0cb4fdd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -48,8 +48,8 @@ - - + + @@ -616,8 +616,8 @@ - - + + diff --git a/ScopeAssessment.py b/ScopeAssessment.py index dfc5a33..327cc16 100644 --- a/ScopeAssessment.py +++ b/ScopeAssessment.py @@ -1,4 +1,4 @@ -__author__ = 'Mica' +# Label the scope of each variable by drawing a box around the range in which it exists and is usable rainbowColors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"] for i in range (7):