python9

= Python - Lesson 7 = Lesson 1 Lesson 2 Lesson 3 Lesson 4 Lesson 5 Lesson 6 Lesson 7 Lesson 8 Lesson 9 Lesson 10

Lesson Objectives

 * Use lists in python
 * Use functions in python
 * Add a while loop in python

Success Criteria
(C-A*) Be able to describe a range of Python syntax (C-A*) Program a working silly sentence in Python

**Starter (10 mins)**
Research/Revise Make a note of the following Python information ==
 * 1) Which brackets go around a list?
 * 2) In python why do you use quotation marks?
 * 3) In python why do you use a hashtag?

==

Homework
On Google Classroom - please check the homework - this weeks is now due after Christmas

Task (35 mins) Using the code window start programming the following silly sentences

Create 3 lists named as follows - I filled in the first line for you....

// name =["Jim","Bob","Fred"] // // verb // // noun //

Add at least 3 words to each list....

Next you need to add the functions to tell python what to do with your lists

// from random import randint #loads the function to generate a random number // // def pick(words): // // num_words = len(words) #finds out how many words are in the list // // num_picked = randint (0, num_words -1) #picks a random number that refers to one of the items in the list // // word_picked = words[num_picked] #stores the random word that has been picked in the variable word picked // // return word_picked //

To print a random silly sentence you run the pick function once for each of the three lists. Use the print command to show the sentence on the screen - to make it make sense you must add the character "a" between your verb and noun

//print(pick(name), pick(verb), "a", pick(noun), end=".\n") #the last part adds a full stop at the end and the \n starts a new line//

Extension Task
Can you add a forever loop to the print command to produce infinate sentences?

Plenary (5 mins)
Check yourself on Python - list the code words you have learned.