Please wait...

Getting Started with Python!

Getting Started with Python!

It’s finally there! Coding Park now supports Python programming language. We have just integrated a brand new Python editor that will allow students write Cody instructions in Python, how cool is that?

Why Python?

Python is one of the most popular computer languages ​​today. It has the advantage of being concise, meaning that you don’t need to write a lot of code to create programs that perform complex tasks. Many large companies, such as Google, NASA, or Amazon, use it to build their programs. Moreover, It can also be used to manage pocket computers, such as the Raspberry Pi.

Today, Python is on the rise for many reasons, one of them is because it is the language of choice for data scientists, who use it to build Artificial Intelligence applications. Such applications address subjects of machine learning, deep learning, scientific computing, and data analysis.

Additionnally, there is a large ecosystem of libraries and tools around Python that help address specific areas of computer science, such as – just to name a few of them :

  • TensorFlow, a deep learning library built for numerical computation using data flow graphs
  • Pandas, which stands for Python Data Analysis, an open source data analysis library
  • Django, a trending open source web application development framework

Finally, for the record, although the Python logo is a snake, its name is actually a tribute to a famous group of British comedians, the Monty Python.

How is Python different from Play pseudocode?

If your child/student has already played with our pseudocode editor, it should be easy for him/her to jump in to Python. Here are some fundamental notions to be aware of.

Indentation

Most of the programming languages like C, C++, and Java use braces { } to define a block of code. Python, however, uses indentation. A code block (body of a function, loop, etc.) starts with indentation and ends with the first unindented line. The amount of indentation is up to you, but it must be consistent throughout that block.

This is a very important notion to know for anyone wanting to start learning Python: the use of the tabulation TAB key is essential as it allows precisely to delimit the borders of code blocks (well, you an also simulate a tabulation with 4 empty spaces). Here is an example:

Notice the highlighted (in blue) empty spaces introduced by the indentation.

In the example above, the right action and the for loop are inside the function definition, so we increase indentation. Then, the jump function is inside the for loop, therefore, the indentation is increased one more time.

Play (pseudocode)Python
Open bracket {Increase indentation : hit RETURN then press TAB
Close bracket }Decrease indentation : hit RETURN then press DEL

Comments

Comments are very important while writing a program. They describe what is going on inside a program, so that a person looking at the code does not have a hard time figuring it out. Python Interpreter ignores comments.

Below an example of a single line comment, it starts with the hash # symbol.

We can write comments that extend up to multiple lines, these multi-line comments are delimited with tripe quotes.

Variables

In Python, there is no keyword to declare a variable. You just have to write the name of a variable. You can also declare a variable, then immediately assign a value to it.

Python is a type-inferred language, so you don’t have to explicitly define the variable type. In the example above, it automatically knows that 1 is a number and declares y variable as a number.

Please note: while in Python variables could be of any type : number, string, boolean, literals, lists, tuples, etc. we narrow down this scope to integers and collections of integers, as our game engine understands only numbers for now.

Functions

In Python, a function is a sequence of statements that performs a specific task. If you have already used the pseudocode editor, you already know how to define functions using the keyword procedure.

Functions help break a program into smaller and modular chunks. As a program grows larger and larger, functions make it readable and easy to understand. Like in Play, a function has a name and a list of parameters (or arguments).

Below an example of a Python function called snake with an input parameter x. Notice the def keyword preceeding the function name, and the x parameter which is used inside as an input parameter of the jump function.

To wrap up, a function definition has the following features:

  1. A keyword def that marks the start of the function definition
  2. A name to uniquely identify the function
  3. Optional parameters through which we pass values to the function
  4. A colon : to mark the beginning of the function body
  5. An optional documentation string (multi-line comment) to describe the function
  6. At least one valid python statement that makes up the function body
  7. An optional return statement to return a value from the function

Please note: while in Play pseudocode editor, the main function is called Cody, we changed that to main.

Below an example of a main function that calls function snake several times with different values of x.

Notice the different syntax colors between a user-defined function snake in black, and a default Cody action function dig in blue.

To be able to use Cody action functions in the Python program, we need to import the library where these functions are defined. Therefore, all Cody programs start with the following import statement, which means we would like to use all (*) the functions (left, right, jump, …) of the default actions library.

That’s all for now as an introductory post of the new Python editor, we will come back later on with more details on the topic.

The editor is already available online, however it is still in beta state!

We are conducting a testing campaing to fully validate it, so if you are interested in using it with your students, do not hesitate to get in touch with the support team, we would be happy to open the catalog throughout the experimentation.

Try Coding Park at home or at school !

Sign up for a free trial, credit card not required

Free Trial