livepython.net

01A program is a list of steps that tells a computer what to do.

What is a program?

a list of steps that tells a computer what to do

02Every app on your phone, every game and every website you visit is a program.

  • apps
  • games
  • websites

03Think of brushing your teeth. Watch the four steps, one after another.

  1. 1Wet the toothbrush
  2. 2Put toothpaste on it
  3. 3Brush your teeth
  4. 4Rinse your mouth
tapyour toothglasstoothpastetoothbrush

04Together, these four steps are the program.

these steps are the program

05The one who follows them, step by step, is the computer.

the computer

follows them

06A computer can't guess. If a step is missing, it won't fill it in: you brush with nothing!

07Swap two steps and you get a strange result. Rinse first, and the toothpaste stays in your mouth!

08So a program must be clear, complete and in the right order.

clear · complete · in order

  1. A program is a list of steps that tells a computer what to do.
  2. Every app on your phone, every game and every website you visit is a program.
  3. Think of brushing your teeth. Watch the four steps, one after another.
  4. Together, these four steps are the program.
  5. The one who follows them, step by step, is the computer.
  6. A computer can't guess. If a step is missing, it won't fill it in: you brush with nothing!
  7. Swap two steps and you get a strange result. Rinse first, and the toothpaste stays in your mouth!
  8. So a program must be clear, complete and in the right order.
1.1  PROGRAMMING

What Is Programming? Explained for Beginners

What Is a Program?

A program is a list of steps that tells a computer what to do. Every app on your phone, every game and every website you visit is a program.

Think of the steps you follow to brush your teeth:

  1. Wet the toothbrush.
  2. Put toothpaste on it.
  3. Brush your teeth.
  4. Rinse your mouth.

These steps are the program. The one who follows them, step by step, is the computer.

Computers are fast, but they can't think

A computer can follow millions of steps every second. But it can't guess what you mean. If a step is missing, it won't fill it in for you. It just does exactly what the steps say.

  • If the steps forget "Put toothpaste on it", you brush with nothing.
  • If "Rinse your mouth" comes first, the toothpaste stays in your mouth.

So a program has to be clear, complete and in the right order.

Programming is the skill of writing these steps in a way a computer can follow. And the good news? You already do this every day. Giving a friend directions to your house is a kind of programming!

A program is a list of steps for a computer: clear, complete and in the right order.

your turnOrder the lines

Put the tooth-brushing steps in order

  1. Put toothpaste on it
  2. Brush your teeth
  3. Rinse your mouth
  4. Wet the toothbrush
These lines are mixed up. Put them back in order, then press Check.
your turnPick the right idea

Which one is a program?

Think about it, then pick one.

01A programmer is the person who writes programs. When you write steps for a computer, that's you!

What does a programmer do?

the person who writes programs

→ that's you!

02A programmer's work is mostly three things. First: write the steps in a programming language.

write

03Then run them, and see what the computer does.

run

04If the result is not what you wanted, fix the steps. Then again, and again!

fix

05A mistake in a program has a funny name: a bug.

1prnt("Hi")

06Finding and fixing a bug is called debugging. Even expert programmers do it many times a day.

debuggingfinding and fixing a bug

07Think of a programmer as a teacher, and the computer as a super-fast student who takes every word literally.

teacher → super-fast student

08If the explanation is clear, the student gets it perfect. If not, the teacher explains again, a little better.

clear → perfect!

unclear → explain again

09You don't need to be a maths genius. You need curiosity, and the patience to try again.

you need curiosity + patience

  1. A programmer is the person who writes programs. When you write steps for a computer, that's you!
  2. A programmer's work is mostly three things. First: write the steps in a programming language.
  3. Then run them, and see what the computer does.
  4. If the result is not what you wanted, fix the steps. Then again, and again!
  5. A mistake in a program has a funny name: a bug.
  6. Finding and fixing a bug is called debugging. Even expert programmers do it many times a day.
  7. Think of a programmer as a teacher, and the computer as a super-fast student who takes every word literally.
  8. If the explanation is clear, the student gets it perfect. If not, the teacher explains again, a little better.
  9. You don't need to be a maths genius. You need curiosity, and the patience to try again.

What Does a Programmer Do?

A programmer is the person who writes programs. So when you write steps for a computer, guess what? You are the programmer!

A programmer's work is mostly three things, again and again:

  1. Write the steps in a programming language.
  2. Run them and see what the computer does.
  3. Fix the steps when the result is not what they wanted.

Fixing is a normal part of the job. Even expert programmers run their code, find a mistake and fix it, many times a day. A mistake in a program has a funny name: a bug. Finding and fixing it is called debugging. You'll learn how to debug in chapter 3.

Think of a programmer as a teacher explaining a task to a super fast student who takes every word literally. If the explanation is clear, the student gets it perfect. If not, the teacher explains again, a little better. That's it: no magic, just clear thinking and patience.

You don't need to be a genius to program. You need clear steps, and patience to fix them.

your turnPick the right idea

Sunny writes steps that make a computer show Hi. Who is the programmer?

Think about it, then pick one.

01Deep inside, a computer only understands machine code: long rows of 0s and 1s.

Programming languages

a computer only understands 0s and 1s

02For example, the word Hi looks like this to a computer.

  • H01001000
  • i01101001

03Writing a whole program like that would take forever.

04And one wrong digit breaks everything: watch H turn into L!

05So people invented programming languages: words people can read, which a computer can be made to understand.

print("Hi")
01110000…

06You write the steps, and a special program turns them into something the computer can run. For Python, it's called the interpreter.

07There are many programming languages: Python, JavaScript, Java, C and more.

  • Python
  • JavaScript
  • Java
  • C
  • and more…

08Each language has its own words and rules, called its syntax.

each one has its own syntax

09Syntax is like grammar: write things the right way, or Python won't understand you.

do ✓  /  don't ✗
print("Hi")Python understands
print HiPython is confused

10Python is one of the easiest languages: its syntax is short and reads a lot like English. That's why this course uses it.

Python reads like English

  1. Deep inside, a computer only understands machine code: long rows of 0s and 1s.
  2. For example, the word Hi looks like this to a computer.
  3. Writing a whole program like that would take forever.
  4. And one wrong digit breaks everything: watch H turn into L!
  5. So people invented programming languages: words people can read, which a computer can be made to understand.
  6. You write the steps, and a special program turns them into something the computer can run. For Python, it's called the interpreter.
  7. There are many programming languages: Python, JavaScript, Java, C and more.
  8. Each language has its own words and rules, called its syntax.
  9. Syntax is like grammar: write things the right way, or Python won't understand you.
  10. Python is one of the easiest languages: its syntax is short and reads a lot like English. That's why this course uses it.

What Is a Programming Language?

Deep inside, a computer only understands machine code: long rows of 0s and 1s. For example, the word "Hi" looks like this to a computer:

01001000 01101001

Writing a whole program like that would take forever, and one wrong digit would break everything. So people invented a better way.

A programming language is a language people can read and write, and a computer can be made to understand. You write your steps in the language, and a special program turns them into something the computer can run. For Python, that special program is called the interpreter.

There are many programming languages: Python, JavaScript, Java, C and more. Each one has its own words and rules, called its syntax (pronounced sin-tax). Syntax is like grammar. In English you say "I am happy", not "happy am I". In Python, you also have to write things in the right way, or Python won't understand you.

Python is one of the easiest languages to start with. Its syntax is short, and it reads a lot like English. That's why this course uses it.

A programming language lets you talk to a computer in words you can read.

your turnPick the right idea

Why do we need programming languages?

Think about it, then pick one.

01Time to write some Python! Here is the most famous first program in the world.

Your first line of code

the most famous first program in the world

02Here it is: one line of real Python.

print1show this("Hello, World!"2the text to show)

03The word print means: show this on the screen.

04The text you want to show goes inside the quotes.

05Python runs the line, and the text appears on the screen.

Python runs it
OUTPUTHello, World!

06Look closely: the quotes don't show. They only mark where the text starts and ends.

no quotes on screen !

07That's all you need for now. You'll learn every part of print() in the next chapter.

every part of print() → chapter 2

08You wrote and ran a real program! Every programmer started with this exact line.

welcome to the club!every programmer started with this line

  1. Time to write some Python! Here is the most famous first program in the world.
  2. Here it is: one line of real Python.
  3. The word print means: show this on the screen.
  4. The text you want to show goes inside the quotes.
  5. Python runs the line, and the text appears on the screen.
  6. Look closely: the quotes don't show. They only mark where the text starts and ends.
  7. That's all you need for now. You'll learn every part of print() in the next chapter.
  8. You wrote and ran a real program! Every programmer started with this exact line.

Your First Line of Python Code

Time to write some Python! Here is the most famous first program in the world:

PYTHONedit me
print("Hello, World!")
OUTPUT
Hello, World!

This one line tells Python: show the text Hello, World! on the screen. The word print means "show this", and the text you want to show goes inside the quotes.

That's all you need for now. You'll learn every part of print() in the next chapter.

Now you try

Click the code above and change Hello, World! to something else, like Hello, Sunny!. The output changes as you type. That's real Python, running right here in your browser.

Made a mess? No problem. Press Reset to get the example back. You can't break anything here, so play as much as you like.

You've just done the most important thing: you wrote and ran a real program.

Every programmer in the world started with this exact line. Welcome to the club!

your turnFix the code

Make it say hello to Sunny

YOUR CODEclick and type to edit
YOUR OUTPUT
press Run to see it
EXPECTED OUTPUT
Hello, Sunny!
Change the code so it shows: Hello, Sunny!

01Python runs your code from top to bottom, one line after another, just like you read a page.

Top to bottom

Python runs one line after another

02Python starts at the top line, and runs the lines one by one.

  1. 1print("First")
  2. 2print("Second")
  3. 3print("Third")
OUTPUT

03Each print() shows its text on a new line, in the same order as the code. Look at the matching dots!

same order!

04Now move print("Third") to the top, and run it again. The output changes!

05Python doesn't sort your lines or guess what you meant. It simply follows them in order.

no guessing!

06It's just like brushing your teeth: rinse before you brush, and the result is very different.

  • remember?

rinse before you brush → strange!

07This gets really important in the Variables chapter: one line stores a value, and a later line uses it. Wrong order means an error.

chapter 4: wrong order → error

08Python reads like you do: top to bottom, one line at a time.

top to bottom, one line at a time

  1. Python runs your code from top to bottom, one line after another, just like you read a page.
  2. Python starts at the top line, and runs the lines one by one.
  3. Each print() shows its text on a new line, in the same order as the code. Look at the matching dots!
  4. Now move print("Third") to the top, and run it again. The output changes!
  5. Python doesn't sort your lines or guess what you meant. It simply follows them in order.
  6. It's just like brushing your teeth: rinse before you brush, and the result is very different.
  7. This gets really important in the Variables chapter: one line stores a value, and a later line uses it. Wrong order means an error.
  8. Python reads like you do: top to bottom, one line at a time.

Python Runs Your Code Top to Bottom

Python runs your code from top to bottom, one line after another, just like you read a page.

PYTHONedit me
print("First")
print("Second")
print("Third")
OUTPUT
First
Second
Third

Each print() shows its text on a new line, in the same order as the code.

Order matters

Now try this: in the editor above, move the line print("Third") to the top. Run it, and the output changes. Python doesn't sort your lines or guess what you meant. It simply follows them in order.

It's just like the tooth-brushing steps at the start of this chapter. If you rinse before you brush, the result is very different. Code works the same way.

This becomes really important soon. In the Variables chapter, one line will store a value and a later line will use it. If the lines are in the wrong order, Python tries to use something that doesn't exist yet, and you get an error.

Python reads like you do: top to bottom, one line at a time.

your turnPredict the output

What will this print?

print("Sunny") print("Rocky") print("Lucky")
Your turn! What will this code show on the screen?
your turnOrder the lines

Put the lines in order to print One, Two, Three

  1. print("Three")
  2. print("Two")
  3. print("One")
These lines are mixed up. Put them back in order, then press Check.