Lesson 1 Learning Objectives

Slides:



Advertisements
Similar presentations
Python - Selection Starter
Advertisements

Variables –recap-python
An Introduction to Textual Programming
Introduction to Python
General Programming Introduction to Computing Science and Programming I.
Section 3 Calculations National 4/5 Scratch Course.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
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.
Variables and Expressions CMSC 201 Chang (rev )
Python - Selection Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle.
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.
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.
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
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.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Few More Math Operators
GCSE COMPUTER SCIENCE Practical Programming using Python
Introduction to Programming
Math operations 9/19/16.
Development Environment
GCSE COMPUTER SCIENCE Practical Programming using Python
Software Development.
Introduction to Computing Science and Programming I
Whatcha doin'? Aims: To start using Python. To understand loops.
Microsoft Excel.
Lesson 1 - Sequencing.
Introducing Instructions
Introduction to Python
Lesson 4 - Challenges.
Introduction to Programming
IF statements.
Introduction to Programming
Variables, Expressions, and IO
Lesson 3 - Repetition.
Introduction to Programmng in Python
Functions CIS 40 – Introduction to Programming in Python
Engineering Innovation Center
Learning to Program in Python
Computer Science and an introduction to Pascal
Microsoft Excel All editions of Microsoft office.
Introduction to Programming
Fill the screen challenge!
File Handling Programming Guides.
Learning to Program in Python
Introduction to TouchDevelop
Number and String Operations
Programming In Lesson 3.
Learning Outcomes –Lesson 4
Introduction to Programming
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.
Teaching London Computing
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Introduction to Programming
Introduction to Programming
GCSE Computing Lesson 6.
A look at Python Programming Language 2018.
Programming In Lesson 4.
Introduction to Programming
Beginning Python Programming
Understanding Code Workshop 2.
Introduction to Python
Introduction to Programming
Chapter 1 Introducing Small Basic
Starter.
Hardware is… Software is…
Python Creating a calculator.
Presentation transcript:

Lesson 1 Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

Learning Objectives Starter Task: You are learning to program. What is programming and why is it important to learn how to program? Answer your questions on a word document and discuss your ideas. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

Why should we learn to program? YouTube video to go here.

IDLE Function Program Code The Python IDLE Load It up – you should see a screen like the one shown – this is the Python Shell IDLE stands for “Integrated Development Environment” – it is the place where a set of tools have been created that allow us to code. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

IDLE Function Program Code The Python IDLE Type in the following print(“Game Over”) Then press enter Game Over You have just written your first Python program – well done Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

IDLE Function Program Code Task 1 Try the following programs Print (“Game Over”) PRINT (“Game Over”) print (“Game Over’) print (“Game Over” Why do you think these do not work? Discuss your thoughts with the teacher Learning Objectives To understand: The Python IDLE and how it is used To be able to: Use the IDLE to create a simple program and understand how it worked Key Words IDLE Function Program Code

IDLE Function Program Code Syntax Highlighting Special Python words such as Print are displayed in Purple Strings like “Game Over” are displayed in Green The output or program result – Game Over is displayed in Blue Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

IDLE Function Program Code Python Files When you create a program directly in the Python shell it can be only be used once. You should always create separate Python files that can be saved for use later. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

IDLE Function Program Code Adding Comments To make your program easier to understand you may wish to add comments to a program - this is easy, you simply use the # key print(“Game Over”) # prints onto screen You will notice that your comments are displayed in red – this is another example of Syntax highlighting Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

IDLE Function Program Code Task 3 Main Name program Create a program by open a new Python file. Print out your full name Print out your favourite colour Include a comment Save it in your Python Programming folder as 1.Full name Extension – Use the Python Option menu to configure IDLE further – have a go at the various options available Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

Understanding Variables A variable is a way of labelling and accessing information from a stored location. In the example ‘name’ is the variable. ‘Larry’ is a string that has been assigned to the variable. Changing Larry changes the variable but ‘name’ remains the same. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

Getting User Input If we create the variable as an Input there is a lot more we can do with it. Copy the code shown into a new Python file. Save it as 1.personal greeter Extension Try to add more questions into your program to find out information about someone. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

secondLine = "That tonight's gonna be a good, good night." Extension work Line Breaks / New Lines You can also write your string over several lines by using “\n”. Like this:   firstLine = "I got a feeling,\nThat tonight's gonna be a good night.\n" secondLine = "That tonight's gonna be a good, good night." print(firstLine + secondLine) Try writing a few of your own! Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

Lesson 2

IDLE Function Program Code Starter task On your post it note try to explain the what is meant by: A variable A String Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers. Key Words IDLE Function Program Code

Open Python > IDLE (python GUI) Exercise 1  Try typing each of the following at the command prompt: (press Enter after each 1).  2+2 17-9 16/4 3*7 Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

number1 = input("Please enter a number between 1 & 100 ")) Using integers Copy the code below. number1 = input("Please enter a number between 1 & 100 ")) number2 = input("Please enter a number between 1 & 100 ")) print ("number 1 + number 2 =",number1+number2) Save your program as 2.Adding. Can you spot what has gone wrong? Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

number1 = int(input("Please enter a number between 1 & 100 ")) Using integers Integers are essentially whole numbers. Copy the code below. number1 = int(input("Please enter a number between 1 & 100 ")) number2 = int(input("Please enter a number between 1 & 100 ")) print ("number 1 + number 2 =",number1+number2) Now edit your program so that it treats the data as integers. By putting int( at the front of the input command we are telling Python we want it treat the data as a whole number and not a String(text). For each set of brackets you have opened you must close the same amount at the of the line. Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

Learning Objectives Using integers – Task Subtraction Edit your code to make it subtract the two numbers. Save it as “2.subtraction” and test it works. Multiplication Edit your code to make it multiply the two numbers. Save it as “multiplication” and test it works Division Edit your code to make it divide the two numbers. Save it as “division” and test it works. Mod Edit your code to make it calculate the modulus (remainder) of a division. Save it as “mod.py” and test it works. (Hint: use x%y) Square Edit your code to make it calculate x2. Save it as “square” and test it works. Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

Learning Objectives Using integers – Task 2 Order of Operations / BIDMAS · Brackets · Indices (powers) · Division and Multiplication. Start on the left and work them out in the order that you find them. · Addition and Subtraction. When only addition and subtraction are left in the sum work them out in the order you find them. starting from the left of the sum and working towards the right   Try writing a program that will take a number, multiply by three and then add four. Try writing a program that will take a number, add four and then multiply by three. Put the number 7 into both programs and check that they work correctly. Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

Lesson 3 Learning Objectives To understand what a selection means in programming . To be able to create Python programs that make use of IF statements.

IDLE Selection IF statement Code Starter task Spot the error in the code on your piece of paper. There are 5 in total. Learning Objectives To understand what a selection means in programming . To be able to create Python programs that make use of IF statements. Key Words IDLE Selection IF statement Code

IDLE Selection IF statement Code Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle. If it’s raining, I’ll ask for a lift. Learning Objectives To understand what a selection means in programming . To be able to create Python programs that make use of IF statements. Key Words IDLE Selection IF statement Code

Learning Objectives IF ... ELSE Create a new file and type in the following code, Save it as 3.IF: hours = int(input(“How many hours a day do you play computer games? “)) if hours < 2: print(“That seems a fairly healthy balance. Well done!”) else: print(“You’re probably good enough by now with all that practice.”)   There are a number of key points here: Notice how the colon (:) is used to say what should happen in each case. Also notice that the indentation is VERY important. Python only knows when your IF statement is finished by looking at the indentation! Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

IF ... ELIF ... ELSE Sometimes there are more than two options: I could walk OR cycle OR get the bus OR get a lift. As well as IF and ELSE, we can stick an ‘ELSE IF’ (or ELIF) in the middle: Create a new file and type in the following code, save it 3.ELIF:   hours = int(input(“How many hours a day do you play computer games? “)) if hours < 2: print(“That seems a fairly healthy balance. Well done!”) elif hours < 4: print(“You’re probably good enough by now with all that practice.”) else: print(“Put the controller down and get some fresh air once in a while!”) Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

There are a couple of important bits here: IF ... ELIF ... ELIF ... ELIF ... ELSE You can include an unlimited number of ELIFs if you need to. Try the following: menu = "What would you like a quote about:\n\ 1. Ability\n\ 2. Boredom\n\ 3. Cats?\n\ 9. Quit\n“ choice = int(input(menu)) if choice == 1: print("Great ability develops and reveals itself increasingly with every new assignment.\n Baltasar”) elif choice == 2: print("The secret of being boring is to say everything.\n Voltaire") elif choice == 3: print("Cats regard people as warmblooded furniture.\n Jacquelyn Mitchard") elif choice == 9: print("Goodbye!!!") There are a couple of important bits here: You can put a line break in your string by using “\n”. You can continue a line of code by putting a “\” at the end. If you are testing for equality, use a double equals (is 3x2 = = 6?) Make your own program that uses a menu system and give the user a response