+ All Categories
Home > Documents > Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen...

Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen...

Date post: 04-Jan-2016
Category:
Upload: andrew-hunter
View: 214 times
Download: 2 times
Share this document with a friend
13
Lesson 6 Year 9 Python School
Transcript
Page 1: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Lesson 6

Year 9 Python School

Page 2: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Objectives.

In this lesson students will learn how to output data to the screen and request input from the user.

Students will also learn how to use variables to store data for use in their programs.

Page 3: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

We will be using Python 3.3 to learn the basic of programming and then have look at other languages if there is time.

We will be using the IDLE Interface

Page 4: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Programming involves using a set of instructions, data and keywords to tell the computer what to do.

Your first program type and then press enter

>>> print(“Hello World”)

Page 5: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Which one of these is correct?

>>> print"Hello World“

>>> print("Hello World");

>>> Print("Hello World")

>>> print("Hel World")

>>> prin(Hello World)

Where do you look for errors?

1) Syntax Errors2) Logical errors

Page 6: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Task

Using a script – create a program that produces three lines of text.

Page 7: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Special characters in text

\n Creates a line in a string of text

\t Creates a tab style indent in a string of text

\\ Allows a backslash to appear in a string of text

\” Allows a speech mark to be used in a string of text

Page 8: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Variables

Variables are containers that can hold data.

In most languages variables are declared to be a certain data type first such as

Strings, Integers, Dates, Real, Characters etc..

In python variables are declared when they have their first value assigned to them

Page 9: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Variables

Try the following program

print("Hello this is a variable program")name = ""name = input("Enter in your name please: ")print("Hello ", name)

Page 10: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Variables

You can use variables to do calculations

Try this program

print("Hello this is a variable program")num1 = 0num2 = 0sum = 0num1 = int(input("Enter in number 1 please: "))num2 = int(input("Enter in number 2 please: "))sum = num1 + num2print("The total is ",sum)

Page 11: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

Tasks

Watch the three python videos under lesson 01 and then answer the questions on the worksheet.

Page 12: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

String Functions.

Len(variable) = returns length

Variable.upper() – returns uppercase of string

Variable.lower() – returns lowercase of string.

Variable.capitalise() – Makes the first letter of the string capital.

Variable.replace(“old word”,”new word”) – Replaces a word in a string with the new word.

Page 13: Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.

Python 3.3

String Functions.

astring = "Hello World"print(astring[:2])print(astring[6:])print(astring[:5])

Output –

HeWorldHello

Can you workout what the code is doing from the output?


Recommended