Top Banner
Introducing Python 3 Introduction to Python
16
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python l1

Introducing Python 3

Introduction to Python

Page 2: Python l1

Let look at how a computer follow instructions,What do you think?

Page 3: Python l1

On the sheets on your desk, Frying an Egg

Sequencing Instructions:What do you think is the correct order for these instructions?

1. Put frying pan on the oven2. Crack open the egg3. Take frying pan out of the cupboard4. Pour oil into the frying pan5. Turn on the oven6. Hold the egg over the frying pan

Page 4: Python l1

The important rules of programming…

• Sequence of Instructions• The order of instructions is

Important• Accuracy is very Important

Page 5: Python l1

Frying an Egg1. Get frying pan2. Put pan on hob3. Turn on hob4. Put oil in pan5. Hold egg over pan6. Break egg

Page 6: Python l1

Example Code

Page 7: Python l1

Python’s Development Environment

• The development program is called the IDLE – Integrated Development Environment

• It has two modes to use:– An Interactive Mode

This lets you see line by line what the results are– Script Mode

This allows you save your program and run it in full

Page 8: Python l1

Screens on,

Open up Python IDE on your computer

Page 9: Python l1

“Hello World!”• This is the most simple program to create.

It is you telling the computer to say ‘Hello World’ to the world.

• In Pythons Interactive Mode type:

print ("Hello World!")

• Press Enter• Try again with some different text.

Page 10: Python l1

Getting it WrongType in these lines of code. There are errors in each one. See what happens• In IDLE type the following erroneous lines:

prilt ("Hello World!")

PRINt ("Hello World!")

print Hello World

print "Hello World!"

Page 11: Python l1

Using Script Mode

• In IDLE, Open a New Window (CTRL + N)• Type:

print ("What is your name?")firstname = input()print ("Hello,",firstname)

• Save the program as MyFirstProgram• Press F5 to Run the program

Page 12: Python l1

What is a variable?• A variable is a location in the computer where you can

temporarily store data for your program• Think of it as an empty cup. The empty cup holds the data

inside it, ready for when your computer needs the information

Page 13: Python l1

Using a Variable to store your name

print ("What is your name?")firstname = input()print ("Hello,",firstname)

Page 14: Python l1

Adding Comments to your code

• Comments are useful when you are programming• They are ignored by the program, they are not counted as code• Comments appear in red• Comments have a # symbol at the start

#name is a variable (or cup!)

print ("What is your name?")name = input()print ("Hello,",name)

Page 15: Python l1

Functions• Functions are special keywords that do a

specific job• Functions appear in purple• print() and input() are examples of functions

print ("What is your name?")firstname = input()print ("Hello,",firstname)

Page 16: Python l1

Lesson Plenary

Remember when you worked out the order to fry an egg?

Write me out a new algorithm, with your choice of what it is based on,

For example, Washing Your Hair