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
LessonScreen(8, "Else and elif statements", self.else_elif),
50
50
LessonScreen(9, "\"WHAT THE HECK IS A METHOD!?!?!?\" (your comments)", self.methods),
51
51
LessonScreen(10, "A function. Ok? I will tell you what a function is.", self.functions),
52
-
LessonScreen(11, "I told you. Object oriented programming is functions. Well, sort of.", self.oop)
52
+
LessonScreen(11, "I told you. Object oriented programming is classes. Well, sort of.", self.oop),
53
+
LessonScreen(12, "Loop-da-loops", self.loops)
53
54
]
54
55
PROJ="Battleship"
55
56
self.p1= [
@@ -72,7 +73,8 @@ def s_init(self, unitNum):
72
73
73
74
defp_init(self, unitNum):
74
75
self.new(0)
75
-
s="self.unit_"+str(unitNum)+"()"
76
+
s="self.proj_"+str(unitNum)+"()"
77
+
print(s)
76
78
exec(s)
77
79
self.master.geometry(self.homeBounds)
78
80
@@ -98,7 +100,7 @@ def syn(self):
98
100
99
101
defvar(self):
100
102
self.new_lesson(1, 3)
101
-
self.multiLbl("Just like literally every single coding language in the world (except for maybe like BASIC and Assembly) and for sure every C based coding language (hint hint: Python is a C-based language), there are variables. There are many different types of variables in Python. Some examples are booleans (coming from Boolean algebra), lambdas (from lambda calculus) and numbers (from litterally every single form of math). Unlike 6th grade math, 7th grade math, 8th grade math, 9th grade math (Algebra I), 10th grade math (Geometry), 11th grade math (Algebra II), 12th grade math(Trigonometry?), college math(Calculus, Linear algebra, etc, etc, etc, and etc.), and some high school and college science(physics), variables in coding can have names longer than 1 letter with subscript. The only downside is that it takes up memory, and it takes up soooo mmuch storage. Like entire bytes. Soooooooo much!!!")
103
+
self.multiLbl("Just like literally every single coding language in the world (except for like binary) and for sure every C based coding language (hint hint: Python is a C-based language), there are variables. There are many different types of variables in Python. Some examples are booleans (coming from Boolean algebra), lambdas (from lambda calculus) and numbers (from litterally every single form of math). Unlike 6th grade math, 7th grade math, 8th grade math, 9th grade math (Algebra I), 10th grade math (Geometry), 11th grade math (Algebra II), 12th grade math(Trigonometry?), college math(Calculus, Linear algebra, etc, etc, etc, and etc.), and some high school and college science(physics), variables in coding can have names longer than 1 letter with subscript. The only downside is that it takes up memory, and it takes up soooo mmuch storage. Like entire bytes. Soooooooo much!!!")
102
104
103
105
defdata_types(self):
104
106
self.new_lesson(1, 4)
@@ -144,29 +146,33 @@ def functions(self):
144
146
defoop(self):
145
147
self.new_lesson(1, 11)
146
148
self.multiLbl("You thought this lesson was going to be about classes? Ha! weeeelllllll, technically object oriented programming is classes. You see, a class has the basic methods and variables. An object is one version of a class. Let me explain and show you the syntax for a class at the same time by making a student class. I'll show you how.")
147
-
code="""class Student:\t\t\t
148
-
\tdef __init__(self, name, grade, gpa):\t
149
-
\t\tself.name = name\t\t\t
150
-
\t\tself.grade = grade\t\t\t
151
-
\t\tself.gpa = gpa\t\t\t\t\t
152
-
\tdef __repr__(self):\t\t\t
149
+
code="""class Student:\t\t\t\t\t
150
+
\tdef __init__(self, name, grade, gpa):\t\t\t
151
+
\t\tself.name = name\t\t\t\t\t\t
152
+
\t\tself.grade = grade\t\t\t\t\t\t
153
+
\t\tself.gpa = gpa\t\t\t\t\t\t\t\t
154
+
\tdef __repr__(self):\t\t\t\t\t\t
153
155
\t\tprint(self.name+" has been in school for "+str(grade+1)+" years and his gpa is "+str(gpa)
154
156
155
-
billy = Student(\"Billy Bob Joe\", 5, 3.95)
156
-
print(billy)"""
157
+
billy = Student(\"Billy Bob Joe\", 5, 3.95)\t\t\t\t
158
+
print(billy)\t\t\t\t\t"""
157
159
self.cenBtn(code, lambda: exec(code))
158
160
self.cenLbl("Two underscores signify a special keyword, and in the case of a class, it's usually a method name. The __init__ method is run as soon as the object is initialized, and it takes in self and whatever other arguments you want it to. Self refers to the class. The __repr__ and __str__ methods are what happen when you want it to be a string, __repr__ is like the official one and __str__ is called when you use str(object_name). You also have __del__ and __call__ and many, many more. You can also create methods but the first argument is always self and to run it from another method in the class, you have to do self.method_name or you can run it like ObjectName.method_name. You can also have static methods which are called by ClassName.method_name(args) and don't have a self. To define a static method, you do @staticmethod above the line with the method.")
159
-
161
+
162
+
defcode(self, code):
163
+
exec(code)
160
164
defloops(self):
161
165
self.new_lesson(1, 12)
162
166
self.multiLbl("I'm doing this out of order but who cares. A loop is something that repeats. There are two types of loops. A for loop and a while loop. This should show you the difference")
163
-
code="""for item in ["Hello,", "World!", "foo", "bar"]:
164
-
\tprint(item)"""
165
-
self.cenBtn(code, lambda: exec(code))
167
+
code="""for i in range(3):
168
+
print(i)
169
+
"""
170
+
btn=Button(self.master, text=code)
171
+
btn.pack(anchor=CENTER)
172
+
btn.bind('<Button-1>', lambdae: exec(code))
166
173
code="""i = 0
167
174
while i < 4:
168
175
\tprint(i)
169
176
i += 1"""
170
177
self.cenBtn(code, lambda: exec(code))
171
178
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.")
0 commit comments