Noadswood Science, 2014.  To know the basics of Python coding and decoding Monday, September 07, 2015.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Noadswood Science,  To understand the flow procedure when writing programs Thursday, January 15, 2015.
James Tam Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Logo Lesson 4 TBE Fall 2004 Farah Fisher. Prerequisites Create basic and complex shapes using Logo procedures Create Logo procedures that use variables.
Logo Lesson 5 TBE Fall 2004 Farah Fisher. Prerequisites  Given a shape, use basic Logo commands and/or a procedure to draw the shape, with and.
Main task -write me a program
Fundamentals of Python: From First Programs Through Data Structures
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Fundamentals of Python: First Programs
An Introduction to Textual Programming
1 iSee Player Tutorial Using the Forest Biomass Accumulation Model as an Example ( Tutorial Developed by: (
Noadswood Science,  To understand what strings are and how decisions are made Thursday, September 17, 2015.
Mini Project II – Drawing Machine
Control Structures FOR Statement Looping.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
Python Basic Syntax. Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello,
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
5-Oct-15 Introduction and Code. Overview In this presentation we will discuss: What is Jeroo? Where can you get it? The story and syntax of Jeroo How.
 We are going to learn about programming in general…How to think logically and problem solve. The programming language we will use is Python. This is.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
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.
By the end of this session you should be able to...
Module 3 Fraser High School. Module 3 – Loops and Booleans import statements - random use the random.randint() function use while loop write conditional.
Basic & Advanced Reporting in TIMSNT ** Part Two **
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.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
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.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Algorithms Writing instructions in the order they should execute.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Make a dice challenge! This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.Copy the code below in.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Sequencing The most simple type of program uses sequencing, a set of instructions carried out one after another. Start End Display “Computer” Display “Science”
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
GCSE Computing: Programming GCSE Programming Remembering Python.
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
31/01/ Selection If selection construct.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
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.
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.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Create Your Own Quiz using_Python KS3 COMPUTING KS3 Computing
Lesson 4 - Challenges.
Advanced Coding Session 5
Lesson 1 An Introduction
IF statements.
Calculus Jeopardy Hosted by Bannon Welcome to Power Jeopardy
Addendum: Due to the breakneck speed at which this game was created, there are an ENORMOUS number of “crackhead” errors. Find them for board trip credit!
Calculus Jeopardy Hosted by Bannon Welcome to Power Jeopardy
Coding Concepts (Basics)
Introduction to TouchDevelop
Introduction to Programming
Mostly Solving Equations
Calculus Jeopardy Hosted by Bannon Welcome to Power Jeopardy
A look at Python Programming Language 2018.
This is a setup file for a Jeopardy game.
For Loops (Iteration 1) Programming Guides.
This is a setup file for a Jeopardy game.
Степень с натуральным показателем
Introduction to Programming
This is a setup file for a Jeopardy game.
Primary School Computing
Jeroo Code 7-Sep-19.
Presentation transcript:

Noadswood Science, 2014

 To know the basics of Python coding and decoding Monday, September 07, 2015

IDE  Using Komodo Edit (the integrated development environment) we are going to build two basics programs…  To get started follow the usual procedure within Komodo Edit  Open the program  Click file new > new from template  Choose the Python template  Click open

IDE

 Remember – there are three steps to follow when using an IDE program Enter the code > Save > Run print(“Hello, World!”) > save hello.py > run command hello.py *It is also really important to be careful of spacing and indenting when using Python > for now follow exactly the code shown! **Classic errors > upper and lower case Print and print; single and double quotes ‘’ and “”; minus and underscore - and _; and different brackets (), [], and {}

Error Busting  Have you copied exactly the code to enter?  Have you spelled everything correctly?  Are there two quote marks (‘) around the expression you want to print  Do you have extra spaces at the beginning of the line?  Have you checked the lines above and below the highlighted lines?  Have you asked someone else to check the code against what was asked?  Are you using the correct programming language?

Turtle  Python can draw code – in the code below we can ask it to draw a circle…  Enter the code below into Python – try and determine what each part does… from turtle import * pendown() for n in range(24): forward(10) right(15) penup()

Turtle  Python can draw code – in the code below we can ask it to draw a circle…  Enter the code below into Python – try and determine what each part does… from turtle import * pendown() for n in range(24):(range starts a loop) forward(10) right(15)(turns the turtle clockwise 15 o ) penup()

Issue  You may have noticed one significant issue here – as soon as the program is done it closes itself down…  There is a simple script that can be used to keep the information on screen: - input("\n\nPress the enter key to exit.")  The code above says display the statement “Press the enter key to exit” and if the key is pressed then the program will close

Ghosts  The ghost game highlights some of the things to watch out for when writing programs in Python  The game design is simple…  A player must walk through a door (there are three choices)  Behind one of the doors is a ghost  If the door chosen doesn’t have a ghost the player continues to the next door  If the door chosen does have a ghost then the game ends  A score is collected for how many doors were passed before a ghost was encountered

Ghosts #Ghost Game*name of our program (human language) from random import randint print('Ghost Game') feeling_brave = True*ensure capitals are used score = 0 while feeling_brave: ghost_door = randint(1, 3) *this area needs to be indented by 4x spaces print('Three doors ahead...') print('A ghost behind one.') print('Which door do you open?') door = input ('1, 2, or 3?') door_num = int(door) if door_num ==ghost_door: print('GHOST!') feeling_brave = False else:*this area needs to be indented by 4x spaces print('No ghost!') print('You enter the next room.') score = score + 1 print('Run away!')*indents need to be removed print('Game over! You scored', score) input("\n\nPress the enter key to exit.")

Ghosts  When the game is run you will see the following…  The player must enter a number: 1, 2 or 3

Ghosts  If there is no ghost behind the door then you see “No ghost!”  You then get to continue…

Ghosts  If there is a ghost behind the door then you see “GHOST!”  The game is then over – it will tell you a score achieved (the number of times you went through a door without a ghost behind it)

Decoding  The ghost game displays some of the key features of Python  The code structure is very specific: Python uses spaces at the start of lines to work out which instructions belong together  These spaces are known as indents  For example, the code after while feeling_brave: is indented by four spaces to show it is all part of the main loop

Decoding Game set up Main loop Branching part Game ending

Decoding – Game Setup  The instructions only run once – at the beginning of the game  They setup the title, variables and the “randint” command (choosing the random number 1-3 Command: randint generates random numbers Command: print displays text when the game is run This resets the score to 0 #Ghost Game is a comment – this is not shown when the game is run

Decoding – Main Loop  This loop tells the story and receives the player’s guess – it keeps on going as long as there isn’t a ghost behind the door that is picked  When a ghost appears, the “feeling_brave” variables changes to “False” and the loop stops repeating Command: randint(1, 3) selects a random number between 1 and 3 Input asks for the player’s answer print commands display the text onscreen

Decoding – Branching Part  This program takes a different path depending on whether or not there was a ghost behind the door that was picked  If there wasn’t a ghost the player’s score is increased by one, but if there was a ghost, the “feeling_brave” variable is set to “False” This branch runs if there is a ghost behind the door the player picked If there is no ghost the player sees the message “You enter the next room” The score increases by one each time the player enters a room without meeting a ghost

Decoding – Game Ending  This program takes a different path depending on whether or not there was a ghost behind the door that was picked  If there wasn’t a ghost the player’s score is increased by one, but if there was a ghost, the “feeling_brave” variable is set to “False” The score is a variable – it will change depending on how many rooms the player passes through Input asks for the enter key to be typed – the screen will remain open until this is done print commands display the text onscreen