![raspberry pi 3 python text editor raspberry pi 3 python text editor](https://i.ytimg.com/vi/Bvq0LdBn0dY/hqdefault.jpg)
#Raspberry pi 3 python text editor code#
We may want this If command to run more than one line of code, so we need a way to group code into blocks. The colon tells it that we've finished our expression and we're about to tell it what to do. Again, we have to enclose Ben in inverted commas so the computer knows it's text.
![raspberry pi 3 python text editor raspberry pi 3 python text editor](https://files.realpython.com/media/jvanschooneveld-mu-install.6088c4c2695e.png)
= is used to assign a value to a variable, so we need to use something else to check equality. Each symbol or word we use should have precisely one meaning, otherwise things get confusing. Why =? Well, computers (and programmers for that matter) don't deal well with ambiguity. In our case, we'll check if the name entered is a particular value: For example, 1 > 2, or more usefully, num > 2 where num is a variable. Must be replaced with anything that can be true or false. Remember the If block in Scratch? Well, we can use the same thing here. To make it useful, we need to add a decision step, where the computer looks at the input, and performs different actions depending on what it finds. It just follows the same two steps, then finishes. This makes the program a little more functional, but it's still pretty lifeless. hello.py at the command line to run the program.
![raspberry pi 3 python text editor raspberry pi 3 python text editor](https://d1rytvr7gmk1sx.cloudfront.net/wp-content/uploads/2021/02/vs-code-on-r-pi.jpg)
If they are the other way round, the program will throw up an error because we are using a variable before we have created it. Since the computer will run the commands in order, this one needs to be below the previous one. We can then use this variable to make our print statement a little more personal with the line: We have to enclose this in inverted commas so that the computer knows it's a single chunk of text. This line creates the variable name, displays the prompt 'What is your name? ', and stores what the user types in name. Delete the Hello World line (leaving just the shebang), and add the line: However, with Python we'll need to add a variable to store what the user types. This shows us that the system is running properly, but it's not a very useful program.Īs with the Scratch project, we'll add some user input. You should see Hello World! appear on the screen. Next, type this command to run your program: First, type the following command to tell the system the file is executable: To run the program, you need to open a terminal and navigate to where you saved the file (your home folder by default). Leave the second line blank (not strictly necessary, but it makes your code easier to read), and on the third type: print "Hello World!" and save your work in a file called hello.py. There's a long-standing computing tradition of having your first program output "Hello World!", and we're not going to break it here. We can now get onto the guts of programming. You'll need to add it to the start of all your Python programs. This line, rather cryptically called a 'shebang', tells the system to use the program python, in the folder /usr/bin/ to run the file.