Python Programming Introduction to Python programming for KS

  • Slides: 15
Download presentation

Python Programming Introduction to Python programming for KS 3

Python Programming Introduction to Python programming for KS 3

Learning Objectives: We’re learning to develop our understanding of python programming through the following

Learning Objectives: We’re learning to develop our understanding of python programming through the following techniques: • Syntax Errors • Variable names • Comments

Making a sandwich: 1. 2. 3. 4. Eat the sandwich Close the sandwich Sprinkle

Making a sandwich: 1. 2. 3. 4. Eat the sandwich Close the sandwich Sprinkle the cheese Put the two slides of bread on a plate 5. Grate the cheese 6. Cut the sandwich 7. Spread the butter You may remember that programming is sequential…. Put these in the correct order, your teacher may get you to make the sandwich

Logical Errors: • 1 - Put the two slices of bread on a plate

Logical Errors: • 1 - Put the two slices of bread on a plate • 2 – Spread the margarine / butter • 3 – Grate the cheese • 4 – Sprinkle the cheese on the bread • 5 – Close the sandwich • 6 – Cut the sandwich • 7 – Eat the sandwich Remember that programs should be put in the correct order. If they’re not in the correct order, we can have something called a logic error.

What is a program? Open up python IDE and type in the following: Print

What is a program? Open up python IDE and type in the following: Print (“hello world”) What happens, when you press enter?

What is a program? Open up python IDE and type in the following: Print

What is a program? Open up python IDE and type in the following: Print (“hello world”) What happens, when you press enter?

What is a program? Open up python IDE and type in the following: 5+9

What is a program? Open up python IDE and type in the following: 5+9 What happens, when you press enter?

What is a program? Open up python IDE and type in the following: 5+9

What is a program? Open up python IDE and type in the following: 5+9 What happens, when you press enter?

Syntax Errors Within python, there a number of operators and functions which are built

Syntax Errors Within python, there a number of operators and functions which are built into the language. You’ve just seen how it can handle number, do any other operators work? How do we subtract, divide or multiply. You give it a try! Try printing other phrases, do they work? Extension: Now type out: print (hello world) What happens?

Syntax Errors Extension: Now type out: print (hello world) What happens? SYNTAX ERROR Like

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.

Using Variables • Variables are like a bucket, they’re used to store a number,

Using 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. • For example, to create a variable in python we might do the following: • Studentname = (“James”) • This now means that the word James is stored in student name. You can even print it to the screen by doing. Print (Studentname).

Using Variables • You can do the same with numbers, for example: • Number

Using Variables • You can do the same with numbers, for example: • Number 1 = 10 • Number 2 = 20 • Number 3 = 20 + 10 • Print (Number 3)

Combine variables • You can do the same with numbers, for example: • Using

Combine variables • You can do the same with numbers, for example: • Using number 3 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.

Using Variables / Syntax Independent Task • Using what you have learnt see if

Using Variables / Syntax Independent Task • Using what you have learnt see if you can print screen and evidence the following for your teacher. You should evidence this by taking screen shots. • • • Show a syntax error and annotate it to explain it. Show to print text or numbers. Show 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. Extension Leading into next weeks lesson, you will have to know about different types of variables and data types. See if you can research the types available and examples of their use. You could really extend yourself by trying some of the code…