Raspberry Pi_Eng_23.5.5 Learning Python through Game

23.5.5 Learning Python through Game

Raspberry Pi system offers a variety of games by default. Providing games in Raspberry Pi system has another purpose for users as well as for user to enjoy games simply with Raspberry Pi system.

Providing games on Raspberry Pi system has purpose for providing a way to develop the ability to write Python programs through games. To do this, for each game, the system provide an environment that users can interact with games by Python, and users can freely edit program source code for games and execute them.

Raspberry Pi_Eng_23.5.4 Running Python Program

23.5.4 Running Python Program

23.5.4.1 Creating Python Program file in IDLE

If you want to create a Python program file in IDLE, use menu File àNew File. This will open a blank window, which is not an Python prompt, just an empty file. Here, you can write Python code, save it as a file, and run it. Then, the processing result appears in another window. Let’s enter the following sentence into a new window, save it as a file by using menu File à Save or [Ctrl + S], and then run it by using menu Run à Run Module or [F5] key. You can see that the result is displayed in the original Python Shell window.

Raspberry Pi_Eng_23.5.3 Python Syntax

23.5.3 Python Syntax

23.5.3.1 Starting Statement of Python

When writing a Python program, it is a good idea to start with “#!” (shebang). This line tells the operating system where to look for Python files. This line is not needed when executing a program within IDLE or calling “python’ command separately on Terminal, and it is necessary if the program file name is directly called and executed. It is used to allow programs to be executed regardless of where executable files of program written in Python are installed.

Raspberry Pi_Eng_23.5.2 Getting Started of Python

23.5.2 Gettting Started

The best way to learn Python for the first time is through Python IDLE. Python IDLE can be used in window or terminal environments.

23.5.2.1 Starting in the Desktop GUI environment

You can start Python using the desktop or Applications Menu.

Raspberry Pi_Eng_23.5.1 Python Overview

23.5 Python language

23.5.1 Python Overview

23.5.1.1 What is Python?

Python is an advanced programming language developed by Guido van Rossum, a 1991 programmer. It is flexible, powerful, and easy to use. Python currently has been managed by a nonprofit Python Software Foundation and has an open-source and community-based development model.

Raspberry Pi_Eng_23.4.6 Scratch & Robotics and Sensors

23.4.6 Robotics and Sensors

Scratch not only can handle the input and output to the program, but also it can connect to external hardware using the sensor board and robotics system. Thanks to its multi-threaded features and powerful messaging system between processes, Scratch can be used to create amazingly advanced robotics engines, and it will be very easy work to put Raspberry Pi in the heart of a simple robot.

Raspberry Pi_Eng_23.4.5 Explaining How to Write Scratch Program Using Example

23.4.5 Explaining How to Write Program Using Example

Here, we will explain the usage briefly with examples.

23.4.5.1 Moving [Cat] Sprite

The first time Scratch starts, there will be a “cat” in empty Stage. The “cat” is one of Sprites available in Scratch, [Cat] Sprite.

Raspberry Pi_Eng_23.4.4 Basics of Using Scratch Program

23.4.4 Basics of Using Program

23.4.4.1 Concept of Sprite

If a Sprite is defined in Sprite Area, it appears in Stage Area above it and performs various actions. It is like the main character or actor performing on the stage.

Raspberry Pi_Eng_23.4.3 Scratch Overview

23.4.3 Scratch Overview

When the program starts, the following screen appears. This screen is the main screen where you can create and test a necessary program.

Scratch interface

Figure 23‑6 Scratch overview

The screen consists of several main areas. Let’s look at each one.

Raspberry Pi_Eng_23.4.2 Starting Program of Scratch Language

23.4.2 Starting Program

You can start Scratch from desktop or Applications Menu as follows.

Scratch in applications menu

■ Executing Sctarch program in remote connection environment

Note that there is a case where it does not work normally on remote connection. I have searched the Internet for several sources, but the reason for this is still not clear.