Advanced Coding Session 5

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
An Introduction to Textual Programming
ECS 10 10/8. Outline Announcements Homework 2 questions Boolean expressions If/else statements State variables and avoiding sys.exit(…) Example: Coin.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Computer Science 101 Introduction to Programming.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is.
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
IDLE An IDE for Python bundled with the program release Click on IDLE (Python GUI) in the Start menu under the Python program group  Get the IDLE Python.
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.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
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.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
CMSC201 Computer Science I for Majors Lecture 03 – Variables
Introducing Python Introduction to Python.
JavaScript/ App Lab Programming:
You should have C:\100 folder A shortcut to Python IDLE on desktop.
Whatcha doin'? Aims: To start using Python. To understand loops.
A Playful Introduction to Programming by Jason R. Briggs
Introduction to Eclipse
Python Let’s get started!.
Introduction to Python
Introduction to Python
Introduction to Programming
The what of variables Variables are the combination of an identifying label and a value, often a literal like 2 or "hello world". The label/identifier.
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
G7 programing language Teacher / Shamsa Hassan Alhassouni.
Python Mr. Husch.
Today’s lesson – Python next steps
Week 1 Computer Programming Year 9 – Unit 9.04
Number and String Operations
Functions and Procedures
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Teaching London Computing
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Introduction to TouchDevelop
Coding Concepts (Standards and Testing)
Margaret Derrington KCL Easter 2014
A look at Small basic The Text Window 2017.
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Section 1 Introduction To Programming
A look at Python Programming Language 2018.
Python programming exercise
Introduction In today’s lesson we will look at: why Python?
Python Lesson’S 1 & 2 Mr. Kalmes.
Tonga Institute of Higher Education IT 141: Information Systems
Programming In Lesson 4.
Tonga Institute of Higher Education IT 141: Information Systems
Programming In.
Starter Which of these inventions is: Used most by people in Britain
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Advanced Coding Session 5 Royston Shufflebotham

The Story So Far… Created our own blocks in Scratch We can run Python Variables Arithmetic Errors Opening, Finding, Saving Files Python Turtle Graphics

Today Python Creating our own Python Programs from scratch Variable names Blocks & Nesting Conditionals (if)

Quick Python Shell Recap Start up Python Use the IDLE/Shell window to perform a simple calculation: height = 4 width = 5 width * height I know this is ridiculously straightforward, but we’re about to do something different, and I want people to see the big difference between the Shell and a program first hand.

A New Saved Program! Save your program (File->Save) Task: Create a new Python program, Save it, Run it Create a new file (File->New File) Type in our simple program: height = 4 width = 5 width * height Save your program (File->Save) in your own named folder in Documents with the file name first (It will save it as first.py) Run it (Run->Run Module) - what does it produce? What happens? Nothing! When you type commands into the shell, Python tells you the results for every one. In a program, it doesn’t. We need to print the result.

It didn’t do anything!? In the Shell window, Python calculates everything we ask it to, and tells us the answers immediately In a saved Python program, it doesn’t: we need to tell Python when to print something to the screen Task: use a print instruction in your program: print(width * height) Run it again. Any better? I’m going to start calling the IDLE/Shell window just the ‘Shell’ window from now on. It’s the window where you can type in bits of Python and get immediate answers. And we’re going to be jumping about between file editing Windows and the Shell window, so get used to that!

IDLE Help IDLE helps you as you type: Did you notice IDLE helping you as you typed ‘print’? After you type the open bracket, it’ll give you whatever help it can find on that function. As you type functions in IDLE, it’ll try to give you help on the functions you’re using. It can look a little cryptic, but we’ll learn more about them later, and they’ll become very useful. For now, just notice that it gives you confirmation that you’ve got the function name spelled correctly.

Python – Variable Names Can’t just pick any name for a variable in Python like you can in Scratch! Names can Contain letters (uppercase and lowercase) score Contain numbers player2score Contain underscore (‘_’) alien_speed Names can’t Contain anything else! Including spaces! Start with a number Be a ‘reserved’ word Also, Capital letters matter height and Height are different variables! (Normally start lower case in Python, i.e. prefer height) Make sure you know how to type an underscore (SHIFT+-) – you’ll use them a lot!

Python – Good Name, Bad Name Quiz! Are these variable names legal (allowed) or illegal (not allowed)? Width score3 player_score 3rd_name width playerScore PLAYER_SCORE player-score player score If else Good Python Style! “playerScore” is interesting. It’s a common way of naming things in other languages such as JavaScript, JavC, C++, C#, etc and is called ‘camelCase’. It’s not used all that much in Python though. player_score is in a case known as ‘snake case’ PLAYER_SCORE is ‘screaming snake case’, and is used as a convention for names of constants in Python. player-score is ‘kebab case’ “if” would be illegal, but “If” is legal, and Python cares about case. But, whilst legal, “If” would be a really bad name for a variable!