How to start programming with Python, start with the basics! (Part 2)

in #programming6 years ago

In my previous tutorial I showed you how to install Python on your platform of choice.

Today I will be teaching you the basics of Python programming.

1. Open up a preferred IDE (Integrated Development Environment) or a text editor of your choice.

2. Save your program before we even code it

The program should be saved as "myprogram.py" (substitute "myprogram" for whatever name you choose)

3. Let's test that python even works

Type this into your text editor:

print("Hello World"!)

After you write that go into your console and navigate to the folder in which your code is stored.

Then type this command "python myprogram.py" (my program = the name of your program)

This will run your program

Do you notice any errors while executing the command? If so, see if you can fix it yourself.

If you can't fix it yourself the solution is below

On Line 1 there is a syntax error, "print("Hello World"!)" has the exclamation in the wrong place. Change it around so it is like this "print("Hello World!")", ignore the quotations around the code.

Even the smallest errors can ruin your code, it is a good thing to know how to fix them.

Lots of coders will have errors in their projects and sometimes they are as simple as this time, or very complex and takes re-organizing your code to fix it.

Now run your revised code and see what happens.

You should notice the second time you run your code, the console outputs "Hello World!"

This introduction to Python (Part 2) showed you how to output a basic line of text to the console.

Part 3 of this Python series will teach you how to use IF, ELSE, and ELIF in conjuction with INPUT()

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.028
BTC 62984.76
ETH 2472.53
USDT 1.00
SBD 2.55