computer programming task 1 level 6 programming: be able to use a text based language like python...

8
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions with parameters in your programs.

Upload: devyn-bart

Post on 01-Apr-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

COMPUTER PROGRAMMING

Task 1

LEVEL 6 PROGRAMMING:

Be able to use a text based language like Python and JavaScript & correctly use procedures and functions with parameters in your programs.

Page 2: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

Python is a freely available programming language.

You can write Python code in notepad, or any other simple text editors - but it is easier if you use a program like IDLE (named after Eric Idle (Monty Python!))

Page 3: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

You can type simple commands at the prompt (>>>).Try typing:2+217-916/43*7Check that the answers are correct!

Quick note: you are going to be making lots of Python programs. Create a Python folder somewhere so that you can save your files here!

Python is more than a Calculator

This is where we use the function “print” to make something appear on the screen.

Magic pixies inside the computer? - Nope just code!

Page 4: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

Hello World in INTERACTIVE MODE

We can put simple instructions into the IDLE window, but we can’t write and save complex programs.

Open IDLE and look for the chevrons >>>

Simply type the following (exactly):

print(“Hello, World”)

Now press Enter!

The main IDLE window should show you your output:

Well done! You’ve written your first program!

Page 5: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

•Save your program as MyFirstProgram in your PYTHON folder.

(Simply go to File menu….Save As….)

•TO Open the PYTHON program, find the file in your PYTHON folder.

• Right-click the file

• From the pop-up menu, select EDIT with IDLEMake sure you are comfortable with opening and saving a Python program.

>>> print"Hello World">>> print("Hello World");>>> Print("Hello World")>>> print("Hel World")>>> prin(Hello World)

Which one of these will output the following ?

>>>Hello World

By the way… you can use “speech marks” or ‘apostrophes’ for words (strings) Both will work!

Page 6: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

Hello World in SCRIPT MODE

Another way we can write code in PYTHON is by using SCRIPT mode. This is useful when you are working with many lines of code.

Open IDLE and click the FILE menu option. Select NEW WINDOW - this will give you a new window that you can use to write and save your programs!

In this new window, type the following (exactly):

print(“Hello, World”)

Save this file in your Python folder (call it “hello world again.py”) and then press F5 to run it.

The main IDLE window (>>>) should show you your output:

Congratulations! You have written a Python program!

Page 7: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

Task 1: Create a program in python that outputs the following…KEEPCALM ANDLEARN PYTHON

If you can, do all these programs in SCRIPT mode (i.e. go to FILE, NEW WINDOW…then press F5 to run)

Task 2: Create a program in python that outputs the following…I love Python and right now I’m learning to program!

Task 3: Create a program in python that outputs the following…*************************

Save as ‘KeepCalm.py’

Save File again!

What does \n do?

Page 8: COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions

1) Using the escape key \n can you make a Smiley Face?

2) We will be making interactive programs next lesson. How does a Chat Bot work? Click Here

3) Who is Alan Turing?4) Plenary activity from: http://

hcc-c.weebly.com/91.html

Additional Tasks: