Programming Languages. Objectives Understand how programming has evolved Be able to write simple programs using a text based programming language.

Slides:



Advertisements
Similar presentations
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
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.
Evolution and History of Programming Languages Software/Hardware/System.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
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.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
From Scratch to Python Learn to program like the big boys / girls!
Python Programming Fundamentals
An Introduction to Textual Programming
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
Do it now activity Last term we learnt about how data is represented in a computer and about how to identify different volumes of data. How many bits in.
Python From the book “Think Python”
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Evolution and History of Programming Languages. Machine languages Assembly languages Higher-level languages To build programs, people use languages that.
Evolution and History of Programming Languages. Software Programming Language.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
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.
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
PROGRAMMING In. Objectives  We’re learning to develop basic code with the use of the correct syntax and variables. Outcomes  Explain what syntax is.
I Power Higher Computing Software Development Development Languages and Environments.
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.
Software Development. Software Development Loop Design  Programmers need a solid foundation before they start coding anything  Understand the task.
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.
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
NAME Python Programming Workbook Select a Lesson:
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.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Python Lesson 2.
Lecture-8 Introduction to computer languages.
Programming Languages and the Programming Process lesson 28.
GCSE Computing: Programming GCSE Programming Remembering Python.
Getting Started With Python Brendan Routledge
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
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.
 Human language : commonly used to express feeling and understand what other people expression.  Computer language : are a languages by which a user.
Whatcha doin'? Aims: To start using Python. To understand loops.
Lesson 1 - Sequencing.
Week 4 Computer Programming Gray , Calibri 24
Python Let’s get started!.
Learning to Program in Python
Fill the screen challenge!
Today’s lesson – Python next steps
Learning Outcomes –Lesson 4
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.
Topics Introduction Hardware and Software How Computers Store Data
COMPUTER PROGRAMMING PYTHON
Task 1 Computer Programming LEVEL 6 PROGRAMMING:
Introduction to Programming
Week 4 Computer Programming Year 9 – Unit 9.04
A look at Python Programming Language 2018.
Starter answer these questions in your book
Beginning Python Programming
Introduction to Python
Introduction to Programming
Starter Which of these inventions is: Used most by people in Britain
Hardware is… Software is…
Presentation transcript:

Programming Languages

Objectives Understand how programming has evolved Be able to write simple programs using a text based programming language

History Timeline

Machine languages Assembly languages Higher-level languages To build programs, people use languages that are similar to human language. The results are translated into machine code, which computers understand. Programming languages fall into three broad categories: The Evolution of Programming Languages

Machine languages (first-generation languages) are the most basic type of computer languages, consisting of strings of numbers the computer's hardware can use. Different types of hardware use different machine code. For example, IBM computers use different machine language than Apple computers. The Evolution of Programming Languages - Machine Languages

Assembly languages (second-generation languages) are only a bit easier to work with than machine languages. They use English-like phrases to represent strings of numbers. The code is then translated into object code, using a translator called an assembler. They are quite difficult for people to understand The Evolution of Programming Languages - Assembly Languages

Assembler Assembly code Object code

Third-generation languages Fourth-generation languages Fifth-generation languages Higher-level languages are more powerful than assembly language The instructions the programmer uses to write them are more like English so are easier to understand Higher-level programming languages are divided into three "generations," each more powerful than the last: The Evolution of Programming Languages - Higher-Level Languages

FORTANC COBOLC++ BASICJava PascalActiveX The following languages are 3GLs: Higher-Level Languages - Third-Generation Languages

Visual Basic (VB) VisualAge Authoring environments 4GLs may use a text-based environment (like a 3GL) or may allow the programmer to work in a visual environment, using graphical tools. The following languages are 4GLs: Higher-Level Languages - Fourth-Generation Languages

Using Python Learn to Program

Let’s start to program Open the Python IDLE. What does it look like?

Python IDLE

The command prompt

Write your first program >>> print("Hello World") What happens?

Did you get this?

What happens if you type this? >>> print(Hello World)

Oh dear - something is wrong

Syntax errors Computers follow instructions EXACTLY! Computers are not good at dealing with nearly, almost, not quite. Syntax describes the rules that must be used when commands are written.

Different colours are used for different elements to help you. Colours

predict what will happen. >>> print "Hello World" >>> print ("Hello World"); >>> Print ("Hello World") >>> print ("Hel World") >>> prin (Hello World)

find out what happens >>> print "Hello World" >>> print ("Hello World"); >>> Print ("Hello World") >>> print ("Hel World") >>> prin (Hello World)

Debugging Now you know how to spot some errors. This is called DEBUGGING This is really important because you need to know how to correct your mistakes.

Create, save and test a program In IDLE click on File and New Window This is the Edit mode - there is no command prompt

Interactive mode and file editor Think of shopping…… If you are in the interactive mode (IDLE) if you said “buy milk” it would do it straight away, then “buy eggs” etc If you are in the editor it is like making a list of items to buy which will only work when you say “run shopping list”

Using the editor Save the program in your python folder as my_name Then press the f5 key to run the program

What other programs can you write? Add more questions into your my_name program by copying the first lines of code, pasting them and changing the question text.

Using a variable You are now going to use your name variable. Make the program print out the value that the user has saved in name. print (“hello…”) name = input(“What is your name? ”) print (“hello” + name) When you use = it means “make it become …” When you use + in print “…” + “… it means print both these things

print (“hello…” ) name = input(“What is your name?”) print (“hello” + name)

Errors and Debugging print (*hello…* ) name = input(“What is your name?”) print (“hello” + name) Why does it say “Syntax Error on line 1?” python dumbchatterbox.py Syntax Error on Line 1

Errors and Debugging print (“hello…” ) name = input(“What is your name?”) pirnt (“hello” + name) Why does it say “Syntax Error on line 3?” python dumbchatterbox.py Syntax Error on Line 3

Try it out! Can you remember how to save a program file? Which character is not allowed to be used in program file names? Don’t forget to include the.py at the end of the filename! Can you remember how to run a program you have created? Run your program!

What’s wrong? answer = input (Hello would you like to hear a joke?”) PRINT (“you said ”+ ANSWER) print (“Here is the joke …”) answer = input (“Why did the chicken cross the road?”) print (“you said + answer”) print (“To get to the other side!” ) python jokebox.py Error on Line 1 Error on Line 2 Error on Line 5

NEXT STAGE

Build an artificial intelligence program

Edit the program, save as questions

Can you add a summary? Can you create some script at the end of the program that might look something like this….? “So James, it was lovely to meet you. I know that you live in Newport and that your favourite food is pizza”

Research task What is the difference between a variable and a string? Can you identify these in the programs you have written?

Variables – items that can change Variable examples: my_name = input () favourite_food = input () my_age = input () my_school = input ()

Strings – a sequence of characters String examples: “Hello world” “What is your name” “What is your favourite food” “It is good fun talking to chatbots”

Using the Python interpreter as a calculator Go back to the IDLE screen What is 156 add 567? What is 132 subtract 46? What is 256 divided by 8? What is 389 multiplied by 13? Can you work out what mathematical symbols need to be used?

What works? Both of these work

The answers – use brackets!

Integers In computing, whole numbers (without decimals) are referred to as integers, this means that while 4.0 is not considered an integer, 4 is. It is possible to store integers in variables.

Integers stored in variables

IF, Else OR

Who Are You? print (“hello, what is your name”) name = input() if name == (“Mr Richards”): print (“you are ok”) print (“carry on”) else : print (“exterminate!!!“) print (“hello, what is your name”) name = input() if name == (“Mr Richards”): print (“you are ok”) print (“carry on”) else : print (“exterminate!!!“) What will this computer program do? Why do we use one equals sign (name = raw_input…) and two equals signs (if name == “Mr Richards” …)? What will this computer program do? Why do we use one equals sign (name = raw_input…) and two equals signs (if name == “Mr Richards” …)?

Why does this program cause an error? What does the : symbol do? Why does this program cause an error? What does the : symbol do? What’s wrong? print ("hello, what is your name”) name = input() if name = (“Mr Richards“): print ("you are ok“) Else : print (" exterminate!!!“) print ("hello, what is your name”) name = input() if name = (“Mr Richards“): print ("you are ok“) Else : print (" exterminate!!!“) python WhoAreYou.py Error Line 3 SyntaxError: invalid syntax Error Line 5 SyntaxError: invalid syntax

What’s wrong? print (“hello, what is your name”) name = input() if name == (“Mr Richards”): print (“you are ok”) else : print (“exterminate!!!”) print (“hello, what is your name”) name = input() if name == (“Mr Richards”): print (“you are ok”) else : print (“exterminate!!!”) python WhoAreYou.py Error Line 4 IndentationError: expected an indented block Error Line 6 IndentationError: expected an indented block Why does this program cause an error? What does INDENTATION do? Why does this program cause an error? What does INDENTATION do?

What’s wrong? print (“hello, what is your name”) name = input() if answer == (“Mr Richards”) print (“you are ok”) print (“carry on”) else : print (“exterminate!!!”) print (“hello, what is your name”) name = input() if answer == (“Mr Richards”) print (“you are ok”) print (“carry on”) else : print (“exterminate!!!”) python WhoAreYou.py Error Line 3 Syntax error Why does this program cause an error? What is the difference between = and ==? Why does this program cause an error? What is the difference between = and ==?

Lots of decisions? meal = input("What did you eat for breakfast?") if meal == (“nothing“): print (“That's not good, breakfast is important.“) elif meal == ("energy drink“): print ("That's not good. They are bad for you.“) elif meal == ("cereal“): print (“Now that's a good breakfast!“) else : print (“Sorry, I don't know what that is.“) print (“Thank you for taking part.“) meal = input("What did you eat for breakfast?") if meal == (“nothing“): print (“That's not good, breakfast is important.“) elif meal == ("energy drink“): print ("That's not good. They are bad for you.“) elif meal == ("cereal“): print (“Now that's a good breakfast!“) else : print (“Sorry, I don't know what that is.“) print (“Thank you for taking part.“) Use “elif” (else if) Like this … Use “elif” (else if) Like this …

CHALLENGE Make a “Smart Chatterbox” chat program that uses … Print (“…”) Variables raw_input (“…”) if …. : elif …. : else: Make a “Smart Chatterbox” chat program that uses … Print (“…”) Variables raw_input (“…”) if …. : elif …. : else: The Turing test is a test of a machine's ability to exhibit intelligent behaviour, equivalent to or indistinguishable from, that of an actual human. Has any computer ever passed the Turing Test? No. The Loebner Prize awards $5,000 annually for the chatbot which is "most indistinguishable from a human." There is still $100,000 reserved from Dr. Loebner for the first chatbot to actually pass the Turing test. Has any computer ever passed the Turing Test? No. The Loebner Prize awards $5,000 annually for the chatbot which is "most indistinguishable from a human." There is still $100,000 reserved from Dr. Loebner for the first chatbot to actually pass the Turing test.

Comments Comments can be used to make a program easier to understand when someone reads it. A # tells the computer that what follows is a comment The computer ignores the comments

################ # Now add comments to all of your lines of code

Maths Challenge Make a “maths_questions” program that uses … Print (“…”) Variables raw_input (“…”) if …. : else: The program should ask a maths question get and answer and print a suitable message for both the correct and wrong responses Make a “maths_questions” program that uses … Print (“…”) Variables raw_input (“…”) if …. : else: The program should ask a maths question get and answer and print a suitable message for both the correct and wrong responses

Here is the code: save as maths_questions

Add more questions to your game Can you add 5 more maths questions to your game questions?

12 times table Create a test that will check the user’s knowledge of the 12 times multiplication table. The test should have between 4 and 12 questions. Save the file as 12_times_table It must include a header (description, your name and date) You must make use of comments (#)

Can you answer this question? Answer = int(answer) Thinking back to the use of integers in the last lesson, what does this do and what does int mean?

Answer = int(answer) This converts the text string into a number or integer. If it was not converted to an integer, it could not be compared to another integer, the answer 4.

Can you answer this question? if answer ==4: What this mean?

if answer ==4: Carry out the instruction if the answer is 4 == means ‘equal’ to, as in “is it equal to?”

Can you answer this question? What does else mean

else Carry out the instruction if none of the previous if conditions were true

Can you answer this question? Why are the indents necessary after the if and else statements?

Indents This means follow the these instructions if the statement above is true.

Can you answer this question? What happens if the colons are not there after the 4 or else?

Colons You get a syntax error

Final Challenge Invent your own game

Start with a blank file, create your own number game using Python. Add appropriate comments to your game including a header with your name, title and instructions on how to play the game. Add line comments to explain parts of the code. You should include at least 5 questions. Decide what the actual questions are about and the level of difficulty.

Examples How many seconds are there in 1 hour? How many days are there in a leap year? If a triangle has 2 angles of 45 degrees, what will the remaining angle be? If a = 2b – 5 and b = 6, what is a? What is the minimum legal age to vote in the UK? What is converted to denary?

Success criteria Create a game that works and save it Use enough comments to explain how the game works Add a scoring feature to the game Ask the user some questions at the beginning of the game Add a function to report the score at the end of each question Include responsive feedback at the end of the game Include comments to describe what the code does Include a larger set of questions increasing with difficulty Allow the user to try again on a wrong answer, but award a reduced score for a second attempt Give the user feedback midway through the game as encouragement Add some comments explaining how they could add extra features to the game.

Random selection Whose game shall we look at? Let’s look at it together. In pairs, swap over and mark each others work using the criteria. Improve your work based on the feedback you have been given

/handout.html /handout.html Want to learn more? Some useful sites