![]() ![]() Click it again, and both ‘n’ and ‘10’ are placed in the Variables window. Click Step Into and the value will be highlighted. Now let’s run through it one step at a time. >STEP-03 Debug Python code in ThonnyĬhoose View > Variables and a new window appears displaying n and its current value (which is zero). A while loop prints it, and decreases its value as long as it remains above zero. 2, 1, Blast Off!’ The n variable starts at 10. n = 10Ĭlick Run and the code will display ‘10, 9. Create a new script (File > New) and enter the code in countdown.py. ![]() Let’s see how you can walk through a file and see a variable change. Print("Hello " + name) >STEP-02: Coding in Thonny As with IDLE, you can also enter commands directly in the shell, such as: name = "Lucy" Click Run current script (or press F5) to see the output in the shell. Now choose File > Save and name the program hello.py. Enter this line of code in the script editor: print("Hello World!") We’ve used File > Increase Font Size so you can see the text more clearly. >STEP-01: How to use ThonnyĬlick the Raspberry Pi Menu icon in the top left of the screen and choose Programming > Thonny Python IDE. The ability to step through your programs makes it much easier to understand what happens when you hit Run. There’s some pretty good stuff in Thonny for young coders. It also has a range of panels that enable you to inspect various items, such as variables, objects, and the heap (the memory space where items are stored). The approach in Thonny is much more straightforward. You often find debuggers in powerful IDEs, but they tend to require you to manually set breakpoints (places where the program freezes so you can examine the code). Click here to read Object Orientated Programming in issue 54.Click here to read Beginner’s Guide to Coding in issue 53.You can see the variables and objects being created, and values being passed into functions or assessed by comparators. Instead of running your program, it steps through the code line by line. One of the best features is a powerful, but easy-to-use, debug mode. Thonny has a range of additional features that are perfect for learning programming. You can then use the shell to interact directly with the program accessing variables, objects, and other program features. As with Python 2/3 IDLE, you enter a program in the script editor and run it in the shell. When you start Thonny, you’ll see a new script editor and a shell. See also: Programming a Raspberry Pi with Python It offers a lot of advanced features not currently available in the Python 3 (IDLE) program, which is still included with Raspbian. Just open up the program, which you’ll find under Menu > Programming. Thonny comes with Python 3.6 built in, so you don’t need to install anything. Using Thonny, it’s now much easier to learn to code. ![]() Thonny is a new IDE (integrated development environment) bundled with the latest version of the Raspbian with PIXEL operating system. ![]()
0 Comments
Leave a Reply. |