Skip to content

Commit 03f4daa

Browse files
author
Belvedere Tiburon Library CoderDojo
committed
Update files
1 parent 2e5998f commit 03f4daa

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

__pycache__/screens.cpython-35.pyc

13.1 KB
Binary file not shown.

__pycache__/window.cpython-35.pyc

159 Bytes
Binary file not shown.

mainloop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
master.geometry("500x250")
88
app = Screens(master=master)
99
master.mainloop()
10+

screens.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, unit, proj, partTitle, screenFunc):
1919
text = "Unit "+str(unit)+" - "+proj+": "+partTitle
2020
showAs = partTitle
2121
func = screenFunc
22-
super(ProjectScreen, self).__init(title, showAs, func)
22+
super().__init__(text, showAs, func)
2323

2424
class Screens(Window):
2525

@@ -49,7 +49,8 @@ def __init__(self, master=None):
4949
LessonScreen(8, "Else and elif statements", self.else_elif),
5050
LessonScreen(9, "\"WHAT THE HECK IS A METHOD!?!?!?\" (your comments)", self.methods),
5151
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)
5354
]
5455
PROJ = "Battleship"
5556
self.p1 = [
@@ -72,7 +73,8 @@ def s_init(self, unitNum):
7273

7374
def p_init(self, unitNum):
7475
self.new(0)
75-
s = "self.unit_"+str(unitNum)+"()"
76+
s = "self.proj_"+str(unitNum)+"()"
77+
print(s)
7678
exec(s)
7779
self.master.geometry(self.homeBounds)
7880

@@ -98,7 +100,7 @@ def syn(self):
98100

99101
def var(self):
100102
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!!!")
102104

103105
def data_types(self):
104106
self.new_lesson(1, 4)
@@ -144,29 +146,33 @@ def functions(self):
144146
def oop(self):
145147
self.new_lesson(1, 11)
146148
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
153155
\t\tprint(self.name+" has been in school for "+str(grade+1)+" years and his gpa is "+str(gpa)
154156
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"""
157159
self.cenBtn(code, lambda: exec(code))
158160
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+
def code(self, code):
163+
exec(code)
160164
def loops(self):
161165
self.new_lesson(1, 12)
162166
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>', lambda e: exec(code))
166173
code = """i = 0
167174
while i < 4:
168175
\tprint(i)
169176
i += 1"""
170177
self.cenBtn(code, lambda: exec(code))
171178
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.")
172-

0 commit comments

Comments
 (0)