Presentation is loading. Please wait.

Presentation is loading. Please wait.

PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.

Similar presentations


Presentation on theme: "PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your."— Presentation transcript:

1 PROGRAMMING In Lesson 2

2 STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your self-assessment.

3 OBJECTIVES  Understand that languages have data types  Be able to use the idle editor to save programs  Understand if statement and indentation O UTCOMES  All-Level 4 Know the key data types discussed in lesson To be able to store a user input variable with help Write, save and run your first python program  Most-Level 5Be able to write a these with little help.  Some-Level 6Independently write these and adapt them

4 LETS RECAP LAST LESSON  What is a program? A program is a sequence of instructions that specifies how to perform a computation.  What is syntax? Refers to the spelling and grammar of a programming language  Variables – Boxes with numbers (or text) in.

5 PROGRAMS  We were not really writing programs last yesterday – they were statements. Programs are a sequence of many statements.  Lets write a program.  Open Idle (start menu, all programs, python 3.3)  Make sure you are in the editor.

6 MY FIRST REAL PORGRAM  Enter the following code print(“What is your name?") name = input() print(“Hello " + name)  Press F5, which runs the program. It will ask you to save it first - save the program into your lesson 2 folder call it hello

7 MY BETTER PROGRAM  See if you can adapt this to ask other questions.  Edit the program in the idle editor  Press f5 to run (and save it)  Write the number of other questions you asked into your self assessment book.

8 DATA TYPES – SAME AS IN DATABASES  Integer 23423.44242  Float 9.43.142.02  String “hello”“python”“4”“23.2”  Boolean TrueFalse  2 is NOT the same as 2.0 which is NOT the same as “2” Integer are whole numbers Float numbers have a decimal point Strings have start and end quotation marks Only has these 2 values

9 OUR FIRST GAME import random print("Hello! What is your name?") myName = input() number = random.randint(1, 10) print("Well, " + myName + ", I am thinking of a number between 1 and 10.") print("Take a guess.") guess = int(input()) if guess == number: print("Good job, " + myName + "! You guessed my number") Type this code into the idle editor Save it as “random one” Press f5 to run it Make sure you have 4 spaces here

10 LETS HAVE A LOOK AT THIS. import random print("Hello! What is your name?") myName = input() number = random.randint(1, 10) print("Well, " + myName + ", I am thinking of a number between 1 and 10.") print("Take a guess.") guess = int(input()) if guess == number: print("Good job, " + myName + "! You guessed my number") We re-using an existing piece of code to give us a random number Generates a random number between 1 and 10 and stores it in the variable number Converts the input from text to an integer The == is equal to

11 THE IF STATEMENT if guess == number: print("Good job, " + myName + "! You guessed my number") The print statement is run ONLY if the condition is True. Starts with if Guess == number the condition that evaluates to either True or False: is the end of the if statement. Notice the spaces. These are very important in python.

12 CONDITIONS Operator Sign Operator Name < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to != Not equal to 6 > 5 3 <= 4 2 == 3 4 = 5 45 != 2 3 == 3.0 Eggs > pizza True False Error, should be == True Error – remember data types Depends on the values of Eggs and pizza variables.

13 INDENTATION – 4 SPACES if 2 == 2: print("Good job, ") print (“you are good”) print (“Are we sure”) Which of these lines of code are run. yes if 24 == 87: print("Good job, ") print (“you are good”) print (“Are we sure”) Which of these lines of code are run. no yes Be very careful with spaces

14 CHALLENGES  Level 4 – Change the range of the random number to 1 to 20 Hint: change this statement number = random.randint(1, 10)  Level 5 - Display the random number if the user does not guess it Hint you might need this part of a statement if guess != number: This statement converts an integer type into a string type. number = str(number)  Level 6 - Let the user have 2 attempts to guess the number

15 PLENARY Update your self-evaluation for this lesson.

16 FUN TIME Try the tangram game Use left mouse button to drag, right mouse button clicks to turn tiles,


Download ppt "PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your."

Similar presentations


Ads by Google