Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Similar documents
Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Decisions, Decisions. Testing, testing C H A P T E R 7

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

the rules The Goal Get all three of your monkeys around the board and into the Banana Grove before anyone else can!

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

T H E I N T E R A C T I V E S H E L L

Text Input and Conditionals

DECIMALS are special fractions whose denominators are powers of 10.

Math Day 2 Programming: How to make computers do math for you

Intro. Scheme Basics. scm> 5 5. scm>

Intro to Python & Programming. C-START Python PD Workshop

Quiz. Introduction: Python. In this project, you ll make a quiz game to challenge your friends. Activity Checklist.

Jython. secondary. memory

Introduction to Programming in Turing. Input, Output, and Variables

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

Real Python: Python 3 Cheat Sheet

CSI Lab 02. Tuesday, January 21st

Introduction to Programming

Spam. Time: five years from now Place: England

Python for Non-programmers

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Making Decisions In Python

UNIT 5. String Functions and Random Numbers

Python Unit

Getting Ready to Teach Unit 1

SYMMETRY v.1 (square)

12 Follow-up Templates

Lesson 2 page 1. ipad # 17 Font Size for Notepad (and other apps) Task: Program your default text to be smaller or larger for Notepad

SPRITES Moving Two At the Same Using Game State

An Introduction to Python for KS4!

MITOCW watch?v=0jljzrnhwoi

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Problem Solving for Intro to Computer Science

Lesson Share TEACHER'S NOTES LESSON SHARE. ing by Olya Sergeeva. Overview. Preparation. Procedure

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 10.

CMSC 201 Computer Science I for Majors

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

In today s video I'm going show you how you can set up your own online business using marketing and affiliate marketing.

Simple Java Programming Constructs 4

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Section 1.1 Definitions and Properties

Inside the World Wide Web Author: Roopa Pai Illustrator: Delwyn Remedios

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Switched-On Schoolhouse 2014 User Guide Resource Center & Messaging System

Clickbank Domination Presents. A case study by Devin Zander. A look into how absolutely easy internet marketing is. Money Mindset Page 1

Introduction to Scratch

Lecture 1: Overview

C Pointers 2013 Author Riko H i

1 Jane s dress is... yours. A the same than B the same to C similar than D similar to

[ the academy_of_code] Senior Beginners

IAE Professional s (02)

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Summer Assignment for AP Computer Science. Room 302

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Python: common syntax

CS1 Lecture 3 Jan. 22, 2018

Excel Basics: Working with Spreadsheets

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Introduction to Programming

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

Boolean Expressions. Is Equal and Is Not Equal

BB4W. KS3 Programming Workbook INTRODUCTION TO. BBC BASIC for Windows. Name: Class:

CMPT 120 Control Structures in Python. Summer 2012 Instructor: Hassan Khosravi

Win-Back Campaign- Re-Engagement Series

Boolean Expressions. Is Equal and Is Not Equal

Media-Ready Network Transcript

Expressions and Casting

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

the NXT-G programming environment

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

1. Please, please, please look at the style sheets job aid that I sent to you some time ago in conjunction with this document.

Introduction to Programming

ORB Education Quality Teaching Resources

ProgressTestA Unit 5. Vocabulary. Grammar

INFINITE CAMPUS MISD ONLINE GRADEBOOK > WEB APPLICATIONS > MANSFIELD

Chapter 1 Operations With Numbers

Introduction to Python (All the Basic Stuff)

Text 1 Cell Phones Raise Security Concerns at School

Name & Recitation Section:

SIMPLE INPUT and OUTPUT:

Programming with Python

Fractions and their Equivalent Forms

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Admin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return

FACULTY AND STAFF COMPUTER FOOTHILL-DE ANZA. FileMaker Pro. Relational Databases

A453 Task 1: Analysis: Problem: Solution:

Assessment - Unit 3 lessons 16-21

Programming for Beginners

Click EDIT to CHANGE ALBUM SHAPE

How to Improve Your Campaign Conversion Rates

PROBLEM SOLVING 11. July 24, 2012

Simplifying IF AND OR Functions with The JayTray

Yup, left blank on purpose. You can use it to draw whatever you want :-)

Transcription:

Name: Date: Instructions: PYTHON - INTRODUCTORY TASKS Open Idle (the program we will be using to write our Python codes). We can use the following code in Python to work out numeracy calculations. Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below. 300+400 987-653 12*9 30/6 Tick here if you managed to do it Instructions: Next, select File > New Window to create a window which you can code into and save Click File > Save and name the file helloworld.py (make sure you ve saved it to an appropriate location - ask your teacher if you are unsure). Practice task - when using the statement print programs will display the text within the quotation marks. Try this by writing the following code:

print ( Hello world! ) TIP: Python is case sensitive so check you have used a lower case letter p! If using version of Python 3.3 or later you must use brackets after the print command. Run a simple hello world program by selecting Run then Run Module. TIP: Remember to run a program you must first save the changes you ve made to your file. NOTE: The program will run in the outer Python window we used earlier (the Python shell). If you have typed the code correctly the program will display the words Hello World! Tick here if you managed to do it Well done you have written your first Python program! Can you write a program which displays longer text and on different lines? For example: Hello, how are you today? I hope you are enjoying this lesson. What shall we code next in Python? TIP: Use the print statement on each new line to display text over several lines Tick here if you managed to do it

Name: Date: Instructions - Declaring variables: Variables may be thought of as boxes within our program where we can place data (numbers or text). We can then use the contents of the boxes within our program and the values assigned to our variable may change as our program runs. When we create a variable and assign data (get a box and put something in it) it is called declaring a variable. To declare a variable we use the following code for example: variable1 = 6 In this example above we have created a variable called variable1 and given it the value of 6. We can create more than one variable and we can assign text as well as numbers to variables e.g. name = John score = 6 PYTHON - TASK SHEET 2 Q. What are the 2 variables that I have created using the code above? Q. What is the value of each variable? Your teacher will now reveal the two answers. Tick here if you got them correct Instructions - Assigning variables: Now create a new Python file called variables.py a) Create a variable called dogs with a value of 12 and a variable called

biscuits with a value of 3. We will be using these variables to write a program that calculates the total number of biscuits required to give x number of biscuits to x number of dogs. Your teacher will now reveal what you should have typed. Tick here if you got it correct Instructions - Comments A comment is a line of code that isn t part of the program but is there to explain to the programmer what parts of the code are doing. We write comments in regular English (or whatever language we as programmers may speak) as opposed to the language of Python. Comments are important as when we write longer pieces of code we may forget the function of different parts, or we may work on code with others and therefore we need to explain what we are doing. However, the trouble with writing in regular English within our program is that our computer thinks we are still writing in Python and may try and interpret commands from what we have said. As such, we need to indicate when we are writing a comment and we do that by using #. The computer will ignore any line starting with # as it knows this is a comment to the programmer and not part of the code. b) Can you now add a comment, using the # symbol for the player and points variables you have created to add an explanation about what we are coding? Your teacher will now reveal what you should have typed. Tick here if you got it correct Instructions - Using mathematical operations and print statement with variables: Task: The purpose of this program is to work out the total number of biscuits required based on the two variables we have declared: the number of dogs and the number of biscuits they each get. To write the program to calculate this, add the following code beneath your variables and comments total = dogs*biscuits print total c) Q. What new variable is being declared? Q. What is the name of this new variable? Q. What mathematical operation can you see here? Q. How would you explain this section of code, what is it asking the computer to do? Q. What do you expect the output of this program to be?

d) Now save your program and select Run then Run Module. Remember, the window you have been coding in will close and your program will run in the outer Python window we used earlier. If you have entered the code correctly your program will display the total number of biscuits required for all dogs - 36 Tick here if you have achieved this Extension: Practice editing your program by changing the values for the two variables. TIP: To modify your program you should return to the window it was written in and make changes before selecting Save then Run then Run Module.. a) Can you write a program to calculate the number of biscuits needed for a children s party if there are 30 children and they each get 4 biscuits each? Tick here if you have achieved this b) Can you write a program to calculate the total number of points 4 teams got in a tournament. Choose your own numbers for how many points each team got! Tick here if you have achieved this c) 5 students make 420 by selling their products. Their total costs were 100. Write a program to calculate how much money they make each after they have paid their costs. Tick here if you have achieved this

Name: PYTHON - TASK SHEET 3 Date: Python has statements, which can be used to accept an input of data from the user. The data which is entered can be used to declare variables. So in other words, rather than saying what the value of the variable is, we can ask the user to enter the data instead. For example, you could type in the following code: name = input ("hello, please enter your name: ) print ("hello, nice to meet you " +name) (Tip: I ve left a space before the last quotation mark to give the user space to enter their name). Q. What do expect to happen when this program is run? Now try running the program and see what happens. Q. What happens? Was your prediction correct? YES/NO TASK: Now try programming a different question which requires the user to input text data, such as the one below. age = input ("how old are you? ") print ("wow you are " +age) Write your own similar code below. Then when you are happy with it type it into Idle and select Save (you could save it as input.py) then select - Run - Run Module. TIP: Just like the example above, make sure; a) The question is inside quotation marks b) The question is also inside brackets Tick here if your program ran correctly

Inputs and mathematical operations: You are now going to write a program which will: 1. Allow the user to enter the number of children in a class 2. Allow the user to enter the number of house points they require each 3. Output the total number of house points required. TASK: Jot down below how you could tackle this coding problem. TIP 1: When typing in the maths calculation you want Python to do, you will need to declare that these are numbers (intergers), otherwise it will recognise them as text (a string) and it won t work. Here is an example children = input ("how many children are there?") sweets = input ("how many sweets do they want?") total= int(children)*int(sweets) print (total, is the number of sweets you will need ) TIP 2: Remember if you want the user to type something in you must use the code =Input ( ) TIP 3: Remember to use # symbol for comment lines (this is to help you or others and doesn t form part of the program). IDEAS - jot your solution ideas below Now try running the program. Q. Is the user asked for the number of children and the number of house points each child requires before the program then outputs the total number of house points required? YES/NO TASK 1: Can you write a program which asks the user to enter how many children are in a class and how many children are in each group? The program should then output how many whole groups there will be. TASK 2: Can you write a program that asks the user how many days there are until half term. You will need to input the right code so that the program output displays this in seconds?

Name: Date: PYTHON - TASK SHEET 4 Conditional statements What the code does sometimes depends on a condition being met or not met. These are called conditional statements (similar to using an if, else block in Scratch). The table below shows the syntax (python language) for comparison operators (what we are comparing the condition to). We will require these to work with our conditional statements. The short piece of code below uses conditional statements and comparison operators. Try inputting the code below into Idle and then save your program and select Run then Run Module #Declare name variable using input from user name = input ( Hi, What is your name? ) print ( It is lovely to meet you, +name) # Declare feeling variable using number input from user feeling = int (input ( How are you feeling today? Excited = 1, Happy = 2, Sad = 3 )) # Use conditional statement with equal to comparison to determine which response is given if feeling == 1: print ( Fantastic. I wonder what you re excited about? ) elif feeling == 2: print ( I am happy too. It s a great day! ) elif feeling == 3: print ( I am sorry to hear that you are miserable. How can I cheer you up?

TASK: In your own words, can you explain below how the above code works? Programming a calculator: Here is a second example which uses a range of comparison operators. In this example the user s inputs also cause the program to perform mathematical operations on the variables declared, like a calculator. Try inputting and running the following code in Idle num1 = input ( Please enter a number ) num2 = input ( Please enter a second number ) if num1 > 100: else: print ( Your first number is greater than 100 ) print ( Your first number is less than 100 ) if num2 > 100: else: print ( Your second number is greater than 100 ) print ( Your second number is less than 100 ) op = input ( Select an operation: 1. Add 2. Subtract 3. Multiply ) if op == 1: add = num1 + num2 print add elif op == 2: sub = num1 num2 print sub elif op == 3: mul = num1*num2 print mul

TASK: In your own, words write an explanation below of what is happening in this piece of code. TASK: Can you program a French dictionary that provides the user with a range of English words to choose from and returns the translation in French? Plan it out below.