Whatcha doin'? Aims: To start using Python. To understand loops.

Slides:



Advertisements
Similar presentations
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Advertisements

PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Python Programming Fundamentals
An Introduction to Textual Programming
Introduction to Python
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
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.
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.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
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.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
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.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PYTHON PROGRAMMING LANGUAGE.
Few More Math Operators
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Introduction to Programming
A Playful Introduction to Programming by Jason R. Briggs
Python: Experiencing IDLE, writing simple programs
Lesson 1 - Sequencing.
Python Let’s get started!.
Introduction to Python
Lesson 4 - Challenges.
Lesson 1 An Introduction
Debugging and Random Numbers
Introduction to Programming
Introduction to Programming
Variables, Expressions, and IO
Computer Programming Methodology Introduction to Java
Introduction to C++ October 2, 2017.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Intro to PHP & Variables
Lesson 1 Learning Objectives
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to Programming
Introduction to Python
Introduction to Programming
An Introduction to Python
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Teaching London Computing
T. Jumana Abu Shmais – AOU - Riyadh
COMPUTER PROGRAMMING PYTHON
Introduction to Programming
Module 4 Loops.
Introduction to Programming
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Section 1 Introduction To Programming
A look at Python Programming Language 2018.
Python programming exercise
Programming In Lesson 4.
Beginning Python Programming
Introduction to Programming
12th Computer Science – Unit 5
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Unit 3: Variables in Java
Introduction to Programming
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Hardware is… Software is…
Programming for Business Computing Introduction
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Whatcha doin'? Aims: To start using Python. To understand loops. Objectives: All: Know the difference between the intepreter and the editor. Most: Type in, save and try out all the examples. Some: Experiment with the interpreter and simple programs.

Python We are going to learn the computer programming language Python. Python is a high-level language created in 1989 by Guido van Rossum. Van Rossum chose that name because he is a fan of “Monty Python”. The home-page for Python is www.python.org. Some people are still using version 2. These lessons assume you are using Python 3.

IDLE When you start Python's built-in IDLE, you'll get an interpreter window first. This is for trying code out immediately. You'll see this prompt: >>> As long as the version you are using starts with 3, everything should work fine. To write a program, choose: File > New Window. Then you'll see this type of window (no prompt).

Mathematical Operators Asterisk means “times”. Forward slash means “divide”. Double forward slash means “integer divide”. Double asterisk means “to the power of”. The percent sign gives you the remainder from doing the division.

Some more operators We use “==” to check if two things are the same. When we ask Python if 2 equals 3, it replies “False”. We use “!=” to check if they are not equal. Less than & less than or equal to. Greater than and greater than or equal to.

We'll do it in the interpreter for now. Print When learning a programming language, it is traditional to find out how to to print “Hello, World!”. We'll do it in the interpreter for now. Experiment Have a go at printing out some other phrases. It won't work if you forget the brackets or the quotation marks.

We are going to learn about the “for” loop. First try this one. For Loops We are going to learn about the “for” loop. First try this one. Don't forget the colon!

Very often, we will use “for” loops with numbers. Try this out – you can experiment with changing the numbers and the bit in quotation marks.

If you don't specify a start point and a step value, Python assumes you want to go up in 1s from 0. Here's how to count down from 10 to 1 in 2s. Task: Write a “for” loop that counts from 1 to 100 in 10s. 0 and 100 must be displayed.

Variables In the loops we have used so far, we made use of variables (they were called “letter”, 'i' and 'x'.) When we make a variable, we ask the computer to set aside a bit of memory to store something. We have a name that points to that area of memory, so that we can get the information out again or change it. Have a go at making some variables and trying out some operations.

Variable Names If you are just using a variable as a counter, it's quite normal to use something very simple, like 'i'. Otherwise, it's a good idea to use a name that helps you to remember what information the variable is holding. Variable names cannot start with numbers and most punctuation marks will cause an error. It's safest to stick with letters, numbers and '_'.

When we want to get some input from the user and put it straight into a variable, we do it this way. Python treats input as strings of characters, if you want to use them as numbers you have to specify that. If we try to divide the string version of '8' we get an error. After we convert it to an integer, using the int() function it works fine.

Our first program. We are going to write a program that will print a multiplication table. The first step is an interpreter version. Notice the colon. Also the lines to be repeated must be indented. The “for” loop makes the variable 'i' take on the values from 2 to 12. The “print()” function displays the strings and numbers and automatically adds a newline. Experiment with the “for” loop and the “print()” function.

I like to start each program with its name as a comment. Let's turn it into a program. First make a “python” folder in your documents. Use File > New Window to open the editor. Save your program as “tables1.py” I like to start each program with its name as a comment. A print() statement to introduce the program. This means, wait for some input from the user and, treating it as a whole number, save it in a variable called 'n'.

Type in the program exactly as it is here. Open a new window. Type in the program exactly as it is here. Save it and press F5 to run it. Check it is working. If it's not, try to fix it (hint – did you type the code it correctly?)

Extension: Write a program which asks the user for his or her name and then says hello to him or her.