NAME Python Programming Workbook Select a Lesson:

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
Fundamentals of Python: From First Programs Through Data Structures
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
An Introduction to Textual Programming
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Python Lesson Week 01. What we will accomplish today Install Python on your computer Using IDLE interactively to explore String Variables if/else while.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Chapter 2 - Algorithms and Design
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Chapter 2: Using Data.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Introduction to Programming with RAPTOR
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
22/11/ Selection If selection construct.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Python Let’s get started!.
NAME Python Programming Workbook Select a Lesson:
31/01/ Selection If selection construct.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Controlling Program Flow with Decision Structures.
GCSE Computing: Programming GCSE Programming Remembering Python.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Getting Started With Python Brendan Routledge
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Select a Lesson: »Lesson 1 Basic syntaxLesson 1 Basic syntax »Lesson 2 Escape sequencesLesson 2 Escape sequences »Lesson 3 Mathematical functionsLesson.
Fundamentals of Programming I Overview of Programming
Whatcha doin'? Aims: To start using Python. To understand loops.
Topics Designing a Program Input, Processing, and Output
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Introduction to Python
IF statements.
The Selection Structure
Variables, Expressions, and IO
Engineering Innovation Center
Fill the screen challenge!
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Learning Outcomes –Lesson 4
If selection construct
If selection construct
Algorithms computer as the tool process – algorithm
Chapter 2: Introduction to C++.
Boolean Expressions to Make Comparisons
Flowcharts and Pseudo Code
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Programming In Lesson 4.
Beginning Python Programming
Hardware is… Software is…
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

NAME Python Programming Workbook Select a Lesson: Lesson 1 Basic syntax Lesson 2 Escape sequences Lesson 3 Mathematical functions Lesson 4 Errors Lesson 5 Variables Lesson 6 Strings Lesson 7 Relational operators Lesson 8 Using ELIF

Lesson 1 Basic Syntax

Activity 1.1- Write a program to print out “Hello World” Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 1.2- Write a program that writes your name on the screen Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 1.3 practice- Copy the following code into python Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 1.3- Write a program that prints your name six times Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Lesson 2 Escape sequenses

Activity 2.1- True or false Are the below statement True or False? Highlight the correct answers! Python was released in 2010 True or false? Python was named after the TV series “Monty Python’s Flying Circus” Python is proprietary software which is expensive to buy Python was written by Bill Gates YouTube is written in Python Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

What does the keyboard shortcut do? Activity 2.2- Keyboard shortcuts Make a note of what these useful keyboard shortcuts do! Keyboard shortcut What does the keyboard shortcut do? Control c   Control v Control a Control x Control f Control n Control p Control s Control z Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 2.3 practice- Copy the following code into python Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Did you have to correct any errors? If so, what were they? Activity 2.3- Write a program that writes four lines of the lyrics of your favourite song on the screen Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 2.4 – Copy and run this program   What happens? 2.What effect does the ”,“ have? Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 2.5 – Escape sequences Escape sequences can be used to alter how the information is displayed on the screen. An escape sequence is a back slash “\”. Experiment with these escape sequences and complete the table. Hint: Use alt p to display the last command entered in the IDLE shell Escape sequence Effect \t   \n \\ \’ \” Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 2.6- Print this text using one line of code Programming screen Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 2.7- Write a program using print commands to display your initials five characters high on the screen. For example: Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Did you have to correct any errors? If so, what were they? Activity 2.7- Write a program using print commands to display your initials five characters high on the screen. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 2.8- An algorithm is a sequence of steps needed to perform a particular task. Algorithms can be represented in different ways. Match the words to the representations on the next three slides. Flowchart Program code Pseudocode Written description Structured English A Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Match the words to the representations. Flowchart Program code Pseudocode Written description Structured English B RECEIVE myName FROM (STRING) KEYBOARD RECEIVE myAge FROM (INTEGER) KEYBOARD SET AgeInTen TOmyAge + 10 SEND myName “will be” AgeInTen “in 10 years time” TO DISPLAY C Write a program that prompts the user to enter their name and age. The program then adds 10 onto the age and displays the text “<name entered> will be <age + 10> in ten years time.”

D E Match the words to the representations. Flowchart Program code Pseudocode Written description Structured English D E If animal has 4 legs then If animal has a tail then If animal answers to “puss” then animal = cat endif

Activity 2.9- Explore ASCII art (Wikipedia) and write a Python program to display your ASCII art creation. For example: Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Did you have to correct any errors? If so, what were they? Activity 2.9- Explore ASCII art (Wikipedia) and write a Python program to display your ASCII art creation. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Mathematical functions Lesson 3 Mathematical functions

Activity 3.1- Copy and run these lines of code. Complete the table to explain what the mathematical operators do. >>> 60/5 >>> 987+34 >>> 564*89 >>> 2**5 >>> 43-5 >>> 11//2 >>> 11%2 Mathematical operator symbol Operation / + * ** - // % Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 3.2- Make up some mathematical calculations of your own and add an example to the table for each mathematical operator. Mathematical operator symbol Example Answer / + * ** - // % Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

The cats have ___ legs in total Activity 3.3.1- Write a program to display this text on the screen and fill in the missing number. 8 cats have 4 legs each The cats have ___ legs in total Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

A farmer with 1089 sheep sells 56 of them Activity 3.3.2- Write a program to display this text on the screen and fill in the missing number. A farmer with 1089 sheep sells 56 of them The farmer has _____ sheep left Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

4 children pick 56 flowers each The children each have ____ flowers Activity 3.3.3- Write a program to display this text on the screen and fill in the missing number. 4 children pick 56 flowers each The children each have ____ flowers Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 3.4- Copy and run these lines of code. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: What effect do the parentheses () have?

Activity 3.5- Predict what you think will be displayed on the screen when this line of code is executed. Prediction Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Now copy and run the code. Explain the answer you get. Is it what you predicted?

Activity 3.6- Make up some multiple-choice questions on precedence. Each question must have four possible answers, one of which is correct. Check your answers are correct by using the interactive Python shell. Try your questions out on other people and document this using the template on the next slide. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: You must be able to explain to them why the answers are correct.

Activity 3.6- Make up some multiple-choice questions on precedence. Outcome Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Can you explain how you got the outcome you did?

Activity 3.7- Devise your own mnemonic for remembering the order of precedence. Python order of precedence Mnemonic Parenthesis (brackets) Exponential Division and multiplication Addition and subtraction Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Lesson 4 Errors

Activity 4.1 - Copy the following code into python Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 4.2 - Copy the following code into python Programming screen| Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 4. 3- Python produces different types of error Activity 4.3- Python produces different types of error. Match up the type of error with its description. Type of error ZeroDivisionError NameError KeyBoardInterrupt TypeError RuntimeError Description of the error Dividing a number by zero. When a program is interrupted from the keyboard by pressing control+c. When a name is used that is not known about (often a variable name that is misspelt). When an operation is attempt that is invalid for that type of data. An error occurs when the program is running. Hint: A full list of Python errors can be found here: http://www.tutorialspoint.com/python/standard_exceptions.htm Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 4.4 - Copy the following code into python Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 4.5 - Copy the following code into python Use Copy this code into the file.   Save the file using file/save. Always give the filename an extension of .py. Use a meaningful filename and store in a suitable folder. Run the commands by using run/run module Close Python and then restart Python, open the file and run the program again. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 4.6 - Copy the following code into python Following the same steps as in Activity 4.5, write a program that displays your name and then your age. Hint: Use file/new window and save the file using file/save. Don’t forget to use a meaningful filename Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 4.7 – Using the python IDLE Write your own summary sheet to describe how to run Python programs, including how to save and open .py files. Include any other commands that you have found useful. Using the Python IDLE   How to open a new window How to save a file How to open a file How to run a program Useful tips alt p Displays the last line you entered Commands in the file are not colour coded Save as a .py file Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Lesson 5 Variables

Activity 5.1 - Where does the name ‘Boolean’ come from? Boolean variables are named after George Boole who invented the mathematics of digital logic. Find a picture of George Boole and insert it here. When was he born? Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 5.2 - Type commands Use the “type” function to find out the data types for these values. Programming screen| Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 5.3 – Type commands The type function returns the data type of an expression. For each of these expressions, first predict the data type then use the type command to see if your prediction was correct. Expression Predicted data type Type command Result “hello world”   type("hello world") False type(False) 15 type(15) 35.6 type(35.6) -999 type(-999) “15” type(“15”) “False” type(“False”) True type(True) 0.001 type(0.001) Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Evidence both python shells the next slide Activity 5.4 - Variables The interactive shell is a useful place to explore variables. Copy and run this code into python. Create a variable called myName and assign it to your name. Create a variable called myAge and assign it to your age Create a variable called myEyes and assign it to your eye colour. Create a variable called myHeight and assign it to your height. Write the commands to display on the screen your name, age, eye colour and height. Evidence both python shells the next slide Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Hint: Remember that a single ‘=’ is used to assign a value to a variable.

Activity 5.4 - Variables Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 5.5 – Variable names A programmer is trying to decide on a valid name for a variable that represents a house number. • Which of the following variable assignments are valid? Why are the others not valid?   Valid or invalid variable name? Reason why not valid 8HouseNumber = 288 houseNumber = 288 house Number = 288 house_number = 288 import = 288 Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: What type of error do you get when using an invalid variable name?

Evidence both python shells the next slide Activity 5.6- Type commands Copy and run this code and explain the result. Amend the program to add another variable called numberThree. Assign the value 76 to this variable. The program should all up all three numbers and print the result. Evidence both python shells the next slide Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 5.6 - Variables Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 5.7 – Data types in Python Complete this table to describe the four data types. Data type Python abbreviat ion Explanation Example integer int   string str float boolean bool Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Hint: Quotation marks are used to show the start and end point of a string, e.g. “this is a string”.

Lesson 6 Strings

Activity 6.1 – Input function The input function allows the user to input a value and assign it to a variable. Copy and run this program. Re-run the program several times, entering different names each time. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Hint: Quotation marks are used to show the start and end point of a string, e.g. “this is a string”.

Activity 6.1.1 - Input function Write a program that asks the user for their name and favourite food and displays these on the screen. Programming screen| Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.2 – Int function The input function allows the user to input a value and assign it to a variable. Copy and run this program. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain why It doesn't work

Activity 6.2.1 – Int function Correct the program from the previous page and display below. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Explain the results

Activity 6.3 – Int function Write a program that asks you to enter a number then displays the number doubled. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.4 – String formatting The string method .format gives you more control over the formatting of your output than printing using space-separated values. The string formatting commands are given in curly brackets {}. Copy the following programs into python and explain what happens and why. Code What happens and why? foodOne="fish" foodTwo="chips" print("{0} and {1}".format(foodOne,foodTwo)) foodTwo="chips” print("{1} and {0}".format(foodOne,foodTwo)) print("{1} {1} {1} and {0} {0 {0}".format(foodOne,foodTwo)) Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 6.4.1 – String formatting Create these variables: one = “cheese” two =”onion”   Use the .formatcommand to display: My favourite crisps are cheese and onion. I love them! cheese and onion and cheese and onion and cheese and onion cheesecheesecheese and oniononiononion You guessed it. The best crisps are onion and … cheese. Display your code on the next slide… Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 6.4.1 – String formatting Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.5 – Formatting numbers You can use the .format method to format the number of decimal places. Copy the following programs into python add the answer and explain what happens and why. Code What happens and why? >>>number = 98.1468297645 >>>print("The answer is {0:.5f}".format(number)) The answer is number = 98.1468297645 print("The answer is {0:.4f}".format(number)) print("The answer is {0:.3f}".format(number)) print("The answer is {0:.1f}".format(number)) print("The answer is {0:.0f}".format(number)) Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 6.5.1 – Formatting numbers Assign the number 765.87641987 to a variable and display the number with 5 decimal places using the .format command. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.5.2 – Formatting numbers Assign the number 765.87641987 to a variable and display the number with 2 decimal places using the .format command. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.5.3 – Formatting numbers Assign the number 765.87641987 to a variable and display the number with no decimal places using the .format command. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.6 – Formatting numbers Write a program that asks how much your bill is at a restaurant and then asks you to enter the % you want to give in a tip. The program should display the amount of tip to give to the waiter. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.6.1 – Formatting numbers Amend the program so that it also displays the total cost of the meal including the tip. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.7 – Formatting numbers Write a program that displays the square of a number. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.7.1 – Formatting numbers Write a program to find the perimeter of a rectangle. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 6.7.2 – Formatting numbers Write a program that finds the area of a square. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Lesson 7 Relational operators

Activity 7.1 – Relational operators Password checking is an example of a relational operator. If the password entered is the same as the password stored then the condition is true. The operator is ‘is equal to’. Brainstorm other examples of condition statements and decide what the operator is. Relation statement Operator Entered password equal to saved password People more than 18 years old can vote Temperature less than zero degrees water freezes Cost of tickets for a concert greater than £30 I cannot afford to go Temperature in the room greater than 23 degrees – open the window Exam result greater than or equal to 75% get an A Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Hint: Greater than is an example of an operator

Activity 7.2 – Relational operators Complete this table of the Python relational operators. Give an example of each and say whether it will evaluate to true or false. Relational operator Operator Example Evaluates to Equal to == “fred” == “sid” False Not equal to Greater than Greater than or equal to Less than Less than or equal to Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Hint: Greater than is an example of an operator

Activity 7.3 – Greater than and less than Find a way that works for you of remembering the difference between “less than” < and “greater than” >. Operator > < Operator meaning Greater than Less than How I remember this Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Hint: As there are only two options you only need to learn one!

Copy and complete the condition to make the program work correctly. Activity 7.4 – Operators This program asks if it is snowing and if so tells you to take a sledge otherwise to have a good day. The condition is missing. Copy and complete the condition to make the program work correctly. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 7.5 – Operators What condition is needed in this program to display ‘pass’ if the exam mark is 40 or more? Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Did you have to correct any errors? If so, what were they? Activity 7.6 – Operators Write a program that asks you to enter the colour of the light at a pedestrian crossing. If the light is green it tells you it is safe to cross, otherwise it tells you to stop. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Did you have to correct any errors? If so, what were they? Activity 7.7 – Operators Write a program that asks you for your password. It then asks you to re-enter your password. If they are the same the message “access granted” is displayed. If the passwords are not the same the message “access denied” is displayed. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Lesson 8 Using ELIF

Activity 8.1– Using elif This program simulates a fortune cookie. A random number is used to decide your ‘fortune’. Copy and run this program. # a random number is given by the randint() function import random answer= random.randint(1,6) if answer == 1: print("You will make a new friend this week") elif answer == 2: print("You will do well in your GCSEs") elif answer == 3: print("You will find something you thought you’d lost")   The program is not yet complete. Include your own ‘fortunes’ for the numbers 4, 5 and 6 and evidence this on the next slide. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 8.1.1– Using elif Include your own ‘fortunes’ for the numbers 4, 5 and 6 and evidence this on the next slide. Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Note: random.randint(1,6) is a function that returns a random number between 1 and 6. The ‘import random’ command allows the program to access the random.randint() function.

Activity 8.2– Writing readable code: a style guide Program code is read more often that it is written. Here are some guidelines on how to write Python code so that it is easy to read. A style guide for Python code Indent by four spaces for each indentation level. Use blank lines to separate different parts of the program. Use two blank lines to separate functions. Choose meaningful names for variables, using CamelCase or with words separated by underscores. Put imports at the top of the file. Include one space around each side of an assignment and other operators. Use complete sentences with the first word capitalised for comments. Write comments that add clarity and explain what the program does. Do not simply repeat what the code already says. Write function names in lowercase, with words separated by underscores. Use meaningful function names which describe the purpose of the function. Write constants in CAPITAL_LETTERS. Use meaningful constant names, which describe the purpose of the constant. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 8.2.1 – Operators Apply the rules in the style guide above for this Python code. def a(s): if s<50: print("You have lost") else: print("You have won") Print screen of amended code using the style guide Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Lesson 9 Flowcharts

Activity 9.1 – Flowcharts Flowcharts can be used to represent algorithms. Identify the flowchart symbols below.. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 9.2 – Flowcharts Study this program and write a program to implement this flowchart, document this on the next slide. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Did you have to correct any errors? If so, what were they? Activity 9.2 – Flowcharts Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 9.3 – Flowcharts Study this flowchart and write a program to implement this flowchart, document this on the next slide. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Did you have to correct any errors? If so, what were they? Activity 9.3 – Flowchart Programming screen Python Shell Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: Did you have to correct any errors? If so, what were they?

Activity 9.3 – Flowcharts Study this flowchart and write a program to implement this flowchart, document this on the next slide. What does this flowchart do? Write the program to implement this flowchart. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments:

Activity 9.5 – Boolean Operators Complete the table using the logical (Boolean) operators AND, OR and NOT. Symbol Description   Returns true if both conditions are true. Returns true if any of the conditions are true. Reverses the outcome of the expression; true becomes false, false becomes true. Assessment: TA/PA/SA Date ??/??/?? Teacher Comments: Students Comments: