18
PROGRAMMING In

PROGRAMMING In. Objectives We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes Explain what syntax is

Embed Size (px)

Citation preview

Page 1: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

PROGRAMMINGIn

Page 2: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

Objectives We’re learning to develop basic code with the use of the correct

syntax and variables.

Outcomes Explain what syntax is and why it’s required. Explain the use of variables.

Page 3: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

OBJECTIVES

Learn about python as a programming language

Learn about expressions & variables and their use

Create several successful programs

OUTCOMES All-State what a programming language is and what a program is. Get

half marks on the test (7/15)

Most- Have used variables and with help get 75% on the test (12/15)

Some- Written their own programs and independently got maximum marks on the test.

Page 4: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

STARTER

Using the internet…Find …

what does “case sensitive” mean what a programming language

is.. 3 benefits of Python

Page 5: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

PYTHON

Python is a programming language A set of words and rules for instructing a computer to

perform specific tasks. The term programming language usually refers to

high-level languages, such as BASIC, C, C++, Python etc Each Programming language has a set of keywords and a

special syntax for writing program instructions.

Page 6: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

Learning to program is going to be fun – so lets keep it simple.

org 100hmain proc mov ah,9 ; mov dx,offset hello_message int 21h : retn hello_message db 'Hello, world!$'main endpend main

print ("Hello, World!“)

#include <iostream>int main(){ std::cout << "Hello World!" << std::endl; return 0;}

C++

Assembler

python

WHY PYTHON

Page 7: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

WHAT IS A PROGRAM

Programming is not telling the computer what you want to do….it is telling it EXACTLY HOW to do it (remember the student robot?!!)

A program is a sequence of instructions that specifies how to perform a computation.

The computation might be something mathematical, such as solving a system of equations

It can also be a symbolic computation, such as searching and replacing text in a document or moving a graphic icon (sprite) on a game.

You can think of a program like a recipe. It contains a list of ingredients called “Variables”. You can store many different types of information in a variable such as:

Data Text Images

A variable on it’s own is like a bucket…. You can get constant variables though…

Page 8: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

TRADITION It is tradition that the first program everyone

creates is to say Hello world”. From the start menu – all programs / python 3.4 /

IDLE MAKE SURE YOU ARE IN THE PYTHON SHELL

Enter the following and press enter

print (“Hello, World”)

This one

If you see this window on top – look for the python shell window.

Page 9: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

EXPRESSIONS – LOOK AT THE EXPRESSIONS BELOW. WHAT ANSWER DO YOU THINK THEY WILL RETURN?

Now try typing these expression in idle, pressing return after each one

print (2+2+2+2+2)

print (8*6)

print (10-5+6)

print ( 2  +       2)

Page 10: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

• EXPRESSIONS

You have been using expressions

2 values and an operator

Even the 2+2+2+2 follows this rule

Operators, you already know.

Perhaps the multiplication is written differently as a * (on the number pad)

At the moment python is acting like a calculator.

2+2 addition

2-2 subtraction

2*2 multiplication

2/2 division

Page 11: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

• SYNTAX

In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language.

Aka syntax means that special key words and characters combine to result in a program.

Page 12: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

• SYNTAX

The syntax of a programming language is the set of rules that control if a program is correct.

You tried print (“Hello, World”) and it worked – a correct program.

Try these

print hello

print (hello)

PRINT(“hello”)

print (a + b)

print (5 + 6 / 7 +)

Syntax is CRITICAL in programming. A computer cannot take an educated guess at your instructions.

Computers just follow exactly what you tell them to do.

Page 13: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

SYNTAX ERRORS

Extension: -

Now type out: print (hello world)

What happens?

SYNTAX ERROR

Like with English, programming languages have their own check similar to a grammar check. When you run code it checks to see whether it is in the form for the computer to compute. If you do not do this the computer throws out an error like above.

Page 14: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

VARIABLES

Variables are like a bucket, they’re used to store a number, data, text or image. You can empty it or refill it as many times as you like.

When we use variable in our code the computer uses the value in the variable.

To store the value 15 in the variable and display it

spam = 15print (spam)

Try it.

Now try these

spam = spam + 12

print (spam)

spam = spam + spam

print (spam)

spam = spam * spam

print (spam)

Page 15: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

VARIABLESThis time we have 2 variables eggs and fizz

You can assign them by

eggs = 15

fizz = 10

What be the output of the following, go on try it.

print( eggs )

print( eggs + fizz )

spam = eggs + fizz

print( spam )

eggs = fizz

print( eggs )

print( EGGS )

1525>>>nothing25>>>nothing10Traceback (most recent call last): File "<pyshell#37>", line 1, in <module> EGGSNameError: name 'EGGS' is not defined

In python eggs is not the same as EGGS.Python is case sensitive which means YOU MUST BE CAREFUL

Page 16: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

COMBINE VARIABLES

You can do the same with numbers, for example:

Using number3 you can combine your sentence with the text you stored in your variable. You could do the same with names or other values. Notice the Comma separating it.

Page 17: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

Show a syntax error and annotate it to explain it. Show how to print text or numbers.Show how to carry out calculations with numbers.Show use of variables through either calculation or text. See if you can make a sentence with the use of two variables.

Page 18: PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is

COMPLETE SELF ASSESSMENT QUIZComplete Self Assessment quiz from lesson 1 folder you copied at the start of the lesson.

And update your self-evaluation for this lesson.