You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: screens.py
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -38,14 +38,14 @@ def new_lesson(self, unit, screenNum):
38
38
#partNum: 0 is what your building, then 1, 2, 3, 4, 5
39
39
defnew_proj(self, unit, partNum):
40
40
self.master.geometry(self.screenBounds)
41
-
projStr="self.p"+unit
41
+
projStr="self.p"+str(unit)
42
42
p=eval(projStr)
43
43
self.new(unit)
44
44
self.cenLbl(p[partNum].title)
45
45
ifpartNum>0:
46
-
self.btnPrev(p[screenNum-1].func)
46
+
self.btnPrev(p[partNum-1].func)
47
47
ifpartNum<len(p)-1:
48
-
self.btnPrev(p[screenNum+1].func)
48
+
self.btnNext(p[partNum+1].func)
49
49
50
50
def__init__(self, master=None):
51
51
self.homeBounds="800x1000"
@@ -208,19 +208,19 @@ def loops(self):
208
208
self.multiLbl("So as you can see, a for loop loops for every item in a list and a while loop repeats while a condition is true. For for loops, a function that is commonly used is range(n). Range makes a list of numbers between 0 (inclusive) and n (exclusive). So range(3) returns [0, 1, 2] and range(1) returns [0]. If you're using for with a dictionary, for thing in dict will make thing the key but for key, value in dict will have key as the key and value as the value. Mind blown. A while loop will run while the condition is True.")
209
209
210
210
211
-
defbs_intro(self):
212
-
self.new_proj(1, 0)
213
-
self.multiLbl("You are going to be building a game that's sort of like this game called battleship. So the computer hides a ship and you have to shoot it down by guessing the row and column correctly.")
214
-
215
-
defbs_empty_list(self):
216
-
self.new_proj(1, 1)
217
-
self.multiLbl("This lesson is pretty self explanatory. Make an empty list called the board. board=[].")
218
-
219
-
defbs_board_list(self):
220
-
self.new_proj(1, 2)
221
-
self.multiLbl("""Now we need to make the list store where the ship is and where you fired and stuff so let's get right to the Chase. Or Wells Fargo. Or whatever bank you use. So, there's this thing I haven't told you. Actually two things. Number 1: If there's a list inside a list, it's called a 2-dimensional list or a 2D list. A list in a list in a list is a 3D list. Etc, etc, etc. The other thing is that you can create lists with multiple copies of the same value by wrapping it in square brackets (as in to create a list of one item) and multiplying it by a certain amount. Let me give you an example. Let's say you wanted a list with 3 "O"s stored in cheerios. You could initialize it like this: cheerios = ["O", "O", "O"] or you could initialize it like this: cheerios = ["O"]*3 and still get the same result. We'll use this when making our board. Instead of doing a manual 2D array and stuff, we're going to do it like this:\nrows = 5\ncols = 5\n board=[["O"]*5]*5 and you will get [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O']]""")
222
-
223
-
defbs_print_board(self):
224
-
self.new_proj(1, 3)
225
-
self.multilbl("""We need a method to print out the board good because we don't want it looking like [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O']]. We want to join it. So the function called print_board which will take one argument, board and will have a for loop in which we are doing a command *for row in board*. The command is a method I haven't told you about yet. It's called join. The syntax is like this: str.join(list). For example, we want to print O O O O O where it's currently printing ['O', 'O', 'O', 'O', 'O'] so we do " ".join(board) to join the board with spaces. That is our command in the for loop.""")
226
-
211
+
defbs_intro(self):
212
+
self.new_proj(1, 0)
213
+
self.multiLbl("You are going to be building a game that's sort of like this game called battleship. So the computer hides a ship and you have to shoot it down by guessing the row and column correctly.")
214
+
215
+
defbs_empty_list(self):
216
+
self.new_proj(1, 1)
217
+
self.multiLbl("This lesson is pretty self explanatory. Make an empty list called the board. board=[].")
218
+
219
+
defbs_board_list(self):
220
+
self.new_proj(1, 2)
221
+
self.multiLbl("""Now we need to make the list store where the ship is and where you fired and stuff so let's get right to the Chase. Or Wells Fargo. Or whatever bank you use. So, there's this thing I haven't told you. Actually two things. Number 1: If there's a list inside a list, it's called a 2-dimensional list or a 2D list. A list in a list in a list is a 3D list. Etc, etc, etc. The other thing is that you can create lists with multiple copies of the same value by wrapping it in square brackets (as in to create a list of one item) and multiplying it by a certain amount. Let me give you an example. Let's say you wanted a list with 3 "O"s stored in cheerios. You could initialize it like this: cheerios = ["O", "O", "O"] or you could initialize it like this: cheerios = ["O"]*3 and still get the same result. We'll use this when making our board. Instead of doing a manual 2D array and stuff, we're going to do it like this:\nrows = 5\ncols = 5\n board=[["O"]*5]*5 and you will get [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O']]""")
222
+
223
+
defbs_print_board(self):
224
+
self.new_proj(1, 3)
225
+
self.multiLbl("""We need a method to print out the board good because we don't want it looking like [['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'], ['O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O']]. We want to join it. So the function called print_board which will take one argument, board and will have a for loop in which we are doing a command *for row in board*. The command is a method I haven't told you about yet. It's called join. The syntax is like this: str.join(list). For example, we want to print O O O O O where it's currently printing ['O', 'O', 'O', 'O', 'O'] so we do " ".join(board) to join the board with spaces. That is our command in the for loop.""")
0 commit comments