Download Programming

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
PROGRAMMING
In
STARTER
Using the internet…Find …
 what does “case sensitive” mean
 what a programming language is..
 3 benefits of Python
OBJECTIVES
 Learn about python as a programming language
 Learn about expressions & variables and their use
 Create several successful programs
SELF ASSESSMENT
 Open the ICT levels spread sheet and find python tab
 Read each Yellow box and answer in the white box.
TARGETS.
 Open the self evaluation workbook and fill in the boxes in green ellipse
(squashed circle)
 This workbook will be used throughout the python unit – DO NOT LOSE
IT. It will be used at the end by the teacher to assess your ICT Level.
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.
WHY PYTHON
org 100h
Assembler
main proc
mov ah,9
;
mov dx,offset hello_message
python
int 21h
:
print ("Hello, World!“)
retn
hello_message db 'Hello, world!$'
main endp
end main
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
C++
}
Learning to program is going to be fun – so lets keep it simple.
WHAT IS A PROGRAM
 Programming is not telling the computer what you want to do….it is
telling it EXACTLY HOW to do it.
 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.
TRADITION
 It is tradition that the first program everyone creates is to say
Hello world”.
 From the start menu – all programs / python 3.3 / idle
 Open Idle(python GUI)
 MAKE SURE YOU ARE IN THE PYTHON SHELL
This one
 Enter the following and press enter
print (“Hello, World”)
If you see this window
on top – look for the
python shell window.
EXPRESSIONS
Try typing some of these expression in idle,
pressing return after each one
print (2+2+2+2+2)
print (8*6)
Remember to press F5
to save the program first
otherwise it won’t run.
print (10-5+6)
print ( 2 +
2)
• 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
• 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.
• 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.
VARIABLES
A variable is just a box with a number in it.
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
Now try these
spam = 15
print (spam)
spam = spam + 12
print (spam)
spam = spam + spam
print (spam)
Try it.
spam = spam * spam
print (spam)
VARIABLES
This 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.
In python
eggs
is not the same as EGGS.
print(
eggs )
15
print( eggs + fizz )
25
>>>nothing
spam = eggs + fizz
MUST
BE
CAREFUL
25
print( spam )
>>>nothing
eggs = fizz
10
print( eggs )
Traceback (most recent call last):
print( EGGS )
File "<pyshell#37>", line 1, in <module>
EGGS
NameError: name 'EGGS' is not defined
Python is case sensitive which means YOU
COMPLETE SELF ASSESSMENT QUIZ
Complete Self Assessment quiz from lesson 1
CHALLENGE TIME
Create a program to calculate the perimeter and area of:
1. A Square
2. A Rectangle
3. A Triangle
4. A Circle
Can you create a program that asks the user to input the length and width
and then the program calculates the perimeter and area for them.
PLENARY
And update your self-evaluation for this lesson.