KS3 Programming Workbook INTRODUCTION TO. Name: Class:

Similar documents
Introduction to Python

Turtle Power. Introduction: Python. In this project, you ll learn how to use a turtle to draw awesome shapes and patterns. Activity Checklist

Python Loops and String Manipulation

Welcome to Introduction to programming in Python

Computer Science for San Francisco Youth

Beginning to Program Python

Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue?

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

2. Setting Up The Charts

STEP 0: OPEN UP THE PYTHON EDITOR. If python is on your computer already, it's time to get started. On Windows, find IDLE in the start menu.

CSC 120: Computer Science for the Sciences (R section)

Exercise 1: Python Language Basics

Advanced Programming with LEGO NXT MindStorms

mouse (or the option key on Macintosh) and move the mouse. You should see that you are able to zoom into and out of the scene.

Quosal Form Designer Training Documentation

Python Lists and Loops

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 5 Program Control

The VB development environment

How To Print To Scale With Easy Blue Print

Chapter 2 Writing Simple Programs

Fruit Machine. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

THE WINNING ROULETTE SYSTEM.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Like any function, the UDF can be as simple or as complex as you want. Let's start with an easy one...

Programming in Access VBA

Excel 2003 A Beginners Guide

Introduction to Python

Your logbook. Choosing a topic

The GED math test gives you a page of math formulas that

Chapter 2. Making Shapes

The phrases above are divided by their function. What is each section of language used to do?

Objectives. Python Programming: An Introduction to Computer Science. Lab 01. What we ll learn in this class

Hello Purr. What You ll Learn

Online Training Welcome Pack

By the end of this workbook I should... What is a Website?

Algebra: Real World Applications and Problems

Website Development Komodo Editor and HTML Intro

Using Microsoft Word. Working With Objects

LabVIEW Day 6: Saving Files and Making Sub vis

Life Insurance Buyer's Guide

Section 1.5 Exponents, Square Roots, and the Order of Operations

Excel 2007 A Beginners Guide

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Internet basics 2.2 Staying safe online. Beginner s guide to. Basics

No Solution Equations Let s look at the following equation: 2 +3=2 +7

How To Turn On A Robot On A Computer On A Black Box On A Pc Or Macbook

Kristen Kachurek. Circumference, Perimeter, and Area Grades Day lesson plan. Technology and Manipulatives used:

VLOOKUP Functions How do I?

Hello. What s inside? Ready to build a website?

Solving systems by elimination

Named Memory Slots. Properties. CHAPTER 16 Programming Your App s Memory

Online Test Monitor Certification Course Transcript

Chapter 2: Software Development in Python

Draw pie charts in Excel

Step 4 Traffic Leads 2 Income AWeber Auto-responder Set-up

Goal: Practice writing pseudocode and understand how pseudocode translates to real code.

WHAT ELSE CAN YOUR HOME PHONE DO?

PIC 10A. Lecture 7: Graphics II and intro to the if statement

SharePoint 2007 Get started User Guide. Team Sites

Working with sections in Word

CHAPTER 8 Presidents Quiz

It was late at night and Smartie the Penguin was WIDE awake He was supposed to be fast asleep but tomorrow was his birthday. He was so excited; all

Numerical integration of a function known only through data points

Lecture 2 Mathcad Basics

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

READING WORKSHOP Mr Jassal Mrs Manning

Information for students about FCE practice tests from

Basic Math for the Small Public Water Systems Operator

Microsoft Outlook Introduction

Pigeonhole Principle Solutions

Please Excuse My Dear Aunt Sally

The Richard Pate School. Draft Year 4 Scheme of Work for Scratch

Unit 7 The Number System: Multiplying and Dividing Integers

VHDL Test Bench Tutorial

GYM PLANNER. User Guide. Copyright Powerzone. All Rights Reserved. Software & User Guide produced by Sharp Horizon.

INTRO TO EXCEL SPREADSHEET

Tutorial 1: The Freehand Tools

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

If you get through this entire PDF and think you did this already and it didn t work then please me at proedgemarketing@gmail.

PYTHON Basics

Writing Macros in Microsoft Excel 2003

Solving Linear Equations in One Variable. Worked Examples

Fusion Voic Plus User Guide For Android Devices

Online Appointments (Patients)

HOW TO SELECT A SCIENCE FAIR TOPIC

SAY IT BETTER IN ENGLISH

Excel Basics By Tom Peters & Laura Spielman

Level 15: Creating a Puzzle

STEAM STUDENT SET: INVENTION LOG

Crop and Frame Your Photos

Maths: How to help your child at home

MICROSOFT POWERPOINT STEP BY STEP GUIDE

Your Portfolio. A portfolio shows examples of your work and may include the following items from events you have planned, or been involved with:

SMARTstuff. The first rule for using an interactive whiteboard is very simple and of the utmost importance: Have faith in yourself you can do this!

Easy Casino Profits. Congratulations!!

HOW TO GET A SOIL MAP FROM THE WEB SOIL SURVEY

a high-level language that translate a set of instructions into! )!<24<=.'8'.!.)$4#)4'!,<),!,&)$*.),'!)!*',!->!2$*,&#?,2-$*!2$,-!5)?<2$'!

Scale Factors and Volume. Discovering the effect on the volume of a prism when its dimensions are multiplied by a scale factor

Unit 5 Length. Year 4. Five daily lessons. Autumn term Unit Objectives. Link Objectives

Transcription:

KS3 Programming Workbook INTRODUCTION TO Name: Class:

Introducing Python Python is a programming language that is easy to learn. It provides a way to write instructions that are simple for a human to understand and clear for the computer to follow. Open up the Python IDLE. You should see this: This is the Shell, which waits for you to type in instructions at the >>> which is called the prompt. Type in print hello world You will need to type it in exactly as you see it here don t put a P instead of a p. Hit Enter and you should see this: Try out a few more print statements. The computer will print out exactly what you put between the and. Type in print 3+4. What happens? Type in print 5*7.

Writing a program So far you have given Python instructions one line at a time that s like you being sent to the shop for one item, then going home again to find out what the next item is! Now we need to learn how to write a list of instructions and give them all to Python at once. On the Shell, click on File/New Window. You should see a completely empty window. Type your code in here. Start each instruction on a new line. Python colours your code so that you can understand it more easily. Anything in green is a String, which means Python treats it as text and will print it exactly as it appears. Click on File/Save as and save your code with the filename test.py. Click on Run/Run Module. You should see your statements appear in the Shell window. Did it work? Congratulations, you ve written your first Python program! Problems? If your program didn t run at all, check very carefully that you have typed it correctly and followed all instructions. If your program runs but the colour coding in the listing disappears, resave your program with a different name and make sure you put.py on the end. This tells the computer that it is a python program and that it should be colour coded to help you.

Programming time 1! Now that you can write your very own program, write a program to solve these problems. Write down your answers. Can you explain what it does? Some are easy, some trickier. Expression Result What does it do? 3+4 57-4 4*6 7/3 7%3 2**3 3==3 3==6 4<6 4>6 4!=6 range(100) Hint: put a print command in front of each of these. You will find it useful to put a string in front of it to explain what it does as well. For example: print 3+4= print 3+4 Or you could put them on the same line by using a, print 3+4=, 3+4

Input in Python (numbers) In order to write a useful program, we need to be able to ask the user questions. This means we need to store their answers as well. We can ask someone their age and store it as a variable called age like this: age=input( How old are you? ) We can then do things with age, like multiply it by 365 to find out your age in days. ageindays=age*365 print You are, ageindays, days old. As we re not allowed spaces in a variable name, we run words together and capitalise the first letter of each word. This is called camel case (full of humps!). Programming time 2! 1. Write a program to work out your age in hours (age*365*24). The age 13 should produce 113880. 2. Write a program to ask for width and height and print out the area of a rectangle (width*height). Width 5 and height 2 should produce area 10. 3. Write a program to ask for time and speed and work out the distance travelled (time * speed). Time 2 and speed 60 should produce distance 120. Make sure that each time you choose a sensible name for your variables.

Input in Python (Text) If we want to input text instead of numbers, we need to use raw_input( ) instead of input( ). name=raw_input( What is your name? ) print Hello, name food=raw_input( What is your favourite food? ) print I like, food, too. Write your own program to respond to the user. True and False in Python You can test something to see if it is true. Python will respond with either True or False. print 3==5 print 5>4 print 2<7 print 2>7 Make up some of your own statements and make sure Python answers right. Making choices in Python We can tell the computer to check something and do something different if it is true or if it is false, by using an IF statement. It will only carry out the indented instructions after the if line if the test is true. You can also include an else: section to tell it what to do if the answer is false.

Look very carefully at the layout of the code, including where : is used and how the code is indented. Also note that we use == (two equals signs) to check if the variable is equal to what we want. We can use IF statements in the same way with numbers. >= means more than or equal to. In maths we would write Programming time 3! 1. Write a program to have a conversation with the computer. It should ask questions and then answer differently according to the answers given. Test your program out on a partner. Does it work? Remember we use raw_input( ) with text. 2. Write a program to have the user input a price. You should then check whether the price is less than 10. If it is, then print You can afford it. Otherwise, print It is too expensive. Remember we use input( ) with numbers. == is equal to!= is not equal to < is less than > is more than <= is less than or equal to >= is more than or equal to We can add more choices by using elif this is short for ELSE IF and we need to do another test with it. if number>50: print Too big elif number < 10: print Too small else: print Just right

Looping in Python for loops We can use a for loop to go through the same section of code more than once. for i in range (10): print hello print finished for i in range (10): print i*5 print finished Note that the loop starts with 0 and ends with 9. Write your own loop to print the 6 times table. Your printout should look like this: 1x6= 6 2X6= 12 3x6= 18 and so on. Looping in Python While loops Sometimes we want to keep on doing something forever, or until something changes. While it s raining, we ll play inside. While it s cheap, we ll buy some. We can do this in Python too. One way to use this is to run a program over and over until the user enters something to stop it. cont= y while cont= y : do whatever the program should do cont=raw_input( Do you want to continue? y/n ) print Thank you for playing. When the user enters anything other than y in response to Do you want to continue? the while loop stops because the test is no longer true. Write a program that starts with 1 and doubles it and displays the results until the user no longer wants to continue.