CODING JOURNAL(CODE MONKEY)
These are the coding concepts that are taught on Banana Tales Part 1 and will be reviewed in this article:
Lists and Indexes - challenges 19 - 25
For Loops - challenges 26 - 30
Range - challenges 31 - 40
Variables - challenges 41 - 47
Conditional Statements (if-else) - challenges 48 - 59
Conditional Loops (while) - challenges 60 - 66
Boolean Operators (and, or, not) - challenges 67 - 78
Functions - challenges 79 - 87
Lists and Indexes - challenges 19 - 25
For Loops - challenges 26 - 30
Range - challenges 31 - 40
Variables - challenges 41 - 47
Conditional Statements (if-else) - challenges 48 - 59
Conditional Loops (while) - challenges 60 - 66
Boolean Operators (and, or, not) - challenges 67 - 78
Functions - challenges 79 - 87
The print() function
The print() function prints the specified message to the screen. The message can be a string (a text surrounded with quotation marks) or a variable.
Place the message inside the parenthesis.
For example:
print("I love Python")
In Banana Tales, the messages are printed in the console. When a challenge is opened, the console tab is closed. If the function print() is used, the console is opened and the messages are displayed.

In programming, it is very common to use prints as a way to debug your program. For example, if you want to know the value of a variable, or to make sure the program reached a certain line of code.
BANANA TALE PART 2
hese are the coding concepts that are taught on Banana Tales Part 2 and will be reviewed in this article:
Classes - challenges 88 - 93
Input - challenges - 94 - 97
Simple Data Types (integers, strings) - challenges 98 - 110
Advanced Data Types (dictionary, set, tuple) - challenges 111 - 128
2d-lists - challenges 129 - 141
Bubble Sort - challenges 142 - 150
Classes - challenges 88 - 93
Input - challenges - 94 - 97
Simple Data Types (integers, strings) - challenges 98 - 110
Advanced Data Types (dictionary, set, tuple) - challenges 111 - 128
2d-lists - challenges 129 - 141
Bubble Sort - challenges 142 - 150
Classes
A Class is a way to bundle functionality together. After defining a class, objects of the class can be created.
A class definition consists of a description on how an object in the class "looks like" (properties) and "behaves like" (methods).
Methods are functions of the class. Properties can be thought of as the variables of the class.
For example, Student can be a class. The properties can be: name (e.g 'John Smith'), grade level (e.g 4), grades (e.g ‘Biology’: ‘B+’, ‘Math’: ‘A’ } ). The methods can be updating the student's grades, calculating the student's average grade, updating the grade level, etc.
A class is defined using the reserved word class. By convention, the class name is capitalized.
The syntax is:
class ClassName:
Once a class is defined, you can create objects of the class. This is called initializing objects.
The syntax is:
object_name = ClassName()
There is one special method called __init__(). This method is called each time an object is initialized. __init__() is a special method for defining and initializing the objects' properties of a class.
The first parameter of any class method is always the object it is operating on, which is written in the method's parenthesis as self.
Usually, the value of the properties will be set when the object is defined. That way, we can create different objects with different values.
If we go back to the student class example, we can define one object with the name "Sara" and one object with the name "John".
The code will be:
class Student:
def __init__(self, name):
self.name = name
student1 = Student("Sara")
student2 = Student("John")
You can define different methods inside the class definition. Each definition starts with the reserved word def and its first parameter is self.
Let's add two methods to the Student class - one to update the grade level; the other to print the student's information.
The code will be:
class Student:
def __init__(self, name):
self.name = name
self.grade_level = 1
def update_grade(self, level):
self.grade_level = level
def print_info(self):
print("Student name: " + self.name)
print("Grade level: " + str(self.grade_level)
student1 = Student("Sara")
Notice the difference between the two new methods - one has just one parameter (self), the other has two. When calling a method, we don't pass a value for self. The number of arguments is always one less than the number of the parameters.
The code to call these two methods will be:
student1.update_grade(4)
student1.print_info()

In Banana Tales, the challenges that practice classes include a drill that needs to drill through some bricks. The class name is Drill. Its properties are x and y. These two properties define where the drill will appear when the code runs and it is initialized. The Drill class has a method drill_right() which moves (drills through bricks if in the way) twice to the right.
You need to initialize objects of Drill that will drill the bricks, thus will lower the buildings and clear the way to the banana.

When initializing an object of Drill, we need to specify the values of x and y that the drill will appear at (upon clicking on run). If you move your mouse across the game area, the x,y coordinates are displayed.
See below how the x,y coordinates are displayed when the mouse hover over the game area (before clicking on run) and how the drill appears (and moves) once we click on run.

A Class is a way to bundle functionality together. After defining a class, objects of the class can be created.
A class definition consists of a description on how an object in the class "looks like" (properties) and "behaves like" (methods).
Methods are functions of the class. Properties can be thought of as the variables of the class.
For example, Student can be a class. The properties can be: name (e.g 'John Smith'), grade level (e.g 4), grades (e.g ‘Biology’: ‘B+’, ‘Math’: ‘A’ } ). The methods can be updating the student's grades, calculating the student's average grade, updating the grade level, etc.
A class is defined using the reserved word class. By convention, the class name is capitalized.
The syntax is:
class ClassName:
Once a class is defined, you can create objects of the class. This is called initializing objects.
The syntax is:
object_name = ClassName()
There is one special method called __init__(). This method is called each time an object is initialized. __init__() is a special method for defining and initializing the objects' properties of a class.
The first parameter of any class method is always the object it is operating on, which is written in the method's parenthesis as self.
Usually, the value of the properties will be set when the object is defined. That way, we can create different objects with different values.
If we go back to the student class example, we can define one object with the name "Sara" and one object with the name "John".
The code will be:
class Student:
def __init__(self, name):
self.name = name
student1 = Student("Sara")
student2 = Student("John")
You can define different methods inside the class definition. Each definition starts with the reserved word def and its first parameter is self.
Let's add two methods to the Student class - one to update the grade level; the other to print the student's information.
The code will be:
class Student:
def __init__(self, name):
self.name = name
self.grade_level = 1
def update_grade(self, level):
self.grade_level = level
def print_info(self):
print("Student name: " + self.name)
print("Grade level: " + str(self.grade_level)
student1 = Student("Sara")
Notice the difference between the two new methods - one has just one parameter (self), the other has two. When calling a method, we don't pass a value for self. The number of arguments is always one less than the number of the parameters.
The code to call these two methods will be:
student1.update_grade(4)
student1.print_info()

In Banana Tales, the challenges that practice classes include a drill that needs to drill through some bricks. The class name is Drill. Its properties are x and y. These two properties define where the drill will appear when the code runs and it is initialized. The Drill class has a method drill_right() which moves (drills through bricks if in the way) twice to the right.
You need to initialize objects of Drill that will drill the bricks, thus will lower the buildings and clear the way to the banana.

When initializing an object of Drill, we need to specify the values of x and y that the drill will appear at (upon clicking on run). If you move your mouse across the game area, the x,y coordinates are displayed.
See below how the x,y coordinates are displayed when the mouse hover over the game area (before clicking on run) and how the drill appears (and moves) once we click on run.

Comments
Post a Comment