Week 4 Computer Programming Gray , Calibri 24

Slides:



Advertisements
Similar presentations
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
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.
Programming Languages. Objectives Understand how programming has evolved Be able to write simple programs using a text based programming language.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Yr 9 a computer science Nice to meet you variable challenge! 1.Variable assessment Looping in python 2.Looping assessment Drawing in python using turtle.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
An Introduction to Textual Programming
Control Structures FOR Statement Looping.
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.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
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.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
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.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
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.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
GCSE Computing: Programming GCSE Programming Remembering Python.
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.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Introduction to Programming
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
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.
Input, Output and Variables GCSE Computer Science – Python.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Introduction to Programming
GCSE COMPUTER SCIENCE Practical Programming using Python
Whatcha doin'? Aims: To start using Python. To understand loops.
Lesson 4 - Challenges.
Selection and Python Syntax
IF statements.
Variables, Expressions, and IO
Lesson 3 - Repetition.
While Loops (Iteration 2)
Lesson 1 Learning Objectives
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Learning to Program in Python
Week 3 Computer Programming Learning Objective:
Fill the screen challenge!
Week 5 Computer Programming Gray , Calibri 24
Week 1 Computer Programming Year 9 – Unit 9.04
Learning Outcomes –Lesson 4
Week 2 Computer Programming Learning Objective:
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.
Week 5 Computer Programming Year 9 – Unit 9.04
Story time Task 5 Computer Programming Gray , Calibri 24
COMPUTER PROGRAMMING PYTHON
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Introduction to TouchDevelop
Introduction to Programming
Week 4 Computer Programming Year 9 – Unit 9.04
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
A look at Python Programming Language 2018.
Starter answer these questions in your book
Python Basics with Jupyter Notebook
Using Script Files and Managing Data
Running a Java Program using Blue Jay.
Introduction to Programming
Week 6 Computer Programming Gray , Calibri 24
Starter Which of these inventions is: Used most by people in Britain
Lecture 7 – Unit 1 – Chatbots Python – For loops + Robustness
Hardware is… Software is…
Iteration – While Loops
Week 6 Computer Programming Year 9 – Unit 9.04
Python Creating a calculator.
Presentation transcript:

Week 4 Computer Programming Gray 80 69 69 69, Calibri 24 Dark Red RGB 153 0 0, Calibri 54

Save the program as MathsQuiz.py Then Run it (Press F5) You are now going to create a new program in Python. Open Python in SCRIPT mode (Click File, then New Window) Enter in the following code carefully. print("What is 2 + 2?") answer = input () answer = int(answer) if answer == 4: print("Well done") else: print("Sorry the answer was 4") Save the program as MathsQuiz.py Then Run it (Press F5)

if answer == 4: else: print("Well done") …a closer look at the code You have just written your first structured program. The if statement is a very, very useful structure to know. When typing it into Python, be very careful not to forget the little colons : if answer == 4: print("Well done") else: print("Sorry the answer was 4")

answer = int(answer) …a closer look at the code print("What is 2 + 2?") answer = input () answer = int(answer) This is an assignment statement just like you have been using before. However, you’ll notice that the variable ‘answer’ is surrounded by brackets and the word ‘int’. Int stands for integer. An integer is just any number without a decimal part. Examples of integers are 75, 2, 100, 55, 16. (12.3 is NOT an integer) Therefore int(answer) converts the variable answer to an integer which is important!

if answer == 4: e.g. my_school = ‘Dalriada’: …a closer look at the code if answer == 4: You’ve probably never seen this before! == A double-equal sign simply means ‘is it equal to?’. e.g. if my_school == ‘Dalriada’: reads as if my school is equal to Dalriada A single-equal sign is only used for assignment. = e.g. my_school = ‘Dalriada’: reads as The variable my_school is assigned Dalriada

IF the answer is equal to 4 THEN ELSE …a closer look at the code if answer == 4: print("Well done") else: print("Sorry the answer was 4") The above section of the code is understood as follows: IF the answer is equal to 4 THEN print ‘Well Done’ ELSE print ‘Sorry the answer was 4’

Look at the program below. For some reason, it won’t run Look at the program below. For some reason, it won’t run!!! Can you spot the 7 mistakes made? You have 2 mins Print('Please enter your name: ') my_name = input print(my_name ' what age are you') my_age = input() my_age = integer(my_age if my_age > 11 print('You must go to Secondary school') else print('You must go to Primary school') 0:40 0:39 0:41 0:42 0:38 0:43 0:44 0:36 0:33 0:32 0:34 0:35 0:45 0:37 0:47 0:55 0:54 0:56 0:57 0:59 0:58 0:53 0:52 0:48 0:31 0:49 0:50 0:51 0:46 0:29 0:10 0:09 0:11 0:12 0:14 0:13 0:08 0:07 0:03 End 0:04 0:05 0:06 0:15 0:16 0:25 0:24 0:26 0:27 0:28 0:23 0:22 0:18 0:17 0:19 0:20 0:21 0:30 1:00 1:41 1:40 1:42 1:43 1:45 1:44 1:39 1:38 1:33 1:01 1:34 1:35 1:37 1:36 1:46 1:47 1:56 1:55 1:57 1:58 2:00 1:59 1:54 1:53 1:49 1:48 1:50 1:51 1:52 1:31 1:32 1:10 1:09 1:11 1:12 1:14 1:13 1:08 1:07 1:03 1:02 1:04 1:05 1:06 1:30 1:15 1:25 1:16 1:26 1:27 1:29 1:28 1:23 1:24 1:22 1:17 1:19 1:20 1:21 1:18 0:02 0:01 Teacher > Click to Start Timer

print('Please enter your name: ') my_name = input() Look at the program below. For some reason, it won’t run!!! Can you spot the 7 mistakes made? The Answers! print('Please enter your name: ') my_name = input() print(my_name, ' what age are you') my_age = input() my_age = int(my_age) if my_age > 11: print('You must go to Secondary school') else: print('You must go to Primary school')

Save as ‘Number_Guess.py’ If you can, do all these programs in SCRIPT mode (i.e. go to FILE, NEW WINDOW…then press F5 to run) Task: Guess the number between 1 & 10 Game. Create a program in python that prompts the user for a number between 1 and 10. The user’s guess, which could be assigned to a variable user_guess, should be compared to the number variable my_number which will be set by the programmer (you). If they guess the correct number, a ‘well done’ message should appear. If they guess wrong, a ‘sorry, better luck next time’ message should appear. Example… Welcome to Guess the Number game! Please enter your guess (between 1 and 10): 7 Well done! You guessed correctly! Save as ‘Number_Guess.py’