1 / 75

Programming Languages

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

latoya
Download Presentation

Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Languages

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

  3. History Timeline

  4. The Evolution of Programming 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: • Machine languages • Assembly languages • Higher-level languages

  5. The Evolution of Programming Languages - Machine 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.

  6. The Evolution of Programming Languages - Assembly 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

  7. Assembly code Assembler Object code

  8. The Evolution of Programming Languages - Higher-Level 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: • Third-generation languages • Fourth-generation languages • Fifth-generation languages

  9. Higher-Level Languages - Third-Generation Languages • The following languages are 3GLs: FORTAN C COBOL C++ BASIC Java Pascal ActiveX

  10. Higher-Level Languages - Fourth-Generation Languages • 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: Visual Basic (VB) VisualAge Authoring environments

  11. Using Python Learn to Program

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

  13. Python IDLE

  14. The command prompt

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

  16. Did you get this?

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

  18. Oh dear - something is wrong

  19. 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. Syntax errors

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

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

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

  23. 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. Debugging

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

  25. 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” Interactive mode and file editor

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

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

  28. 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 Using a variable

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

  30. 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

  31. 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 Errors and Debugging

  32. 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? Try it out! Run your program!

  33. 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 2 Error on Line 5 What’s wrong?

  34. NEXT STAGE

  35. Build an artificial intelligence program

  36. Edit the program, save as questions

  37. 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” Can you add a summary?

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

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

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

  41. 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? Using the Python interpreter as a calculator

  42. Both of these work What works?

  43. The answers – use brackets!

  44. 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

  45. Integers stored in variables

  46. IF, Else OR

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

  48. 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? Why does this program cause an error? What does the : symbol do?

  49. 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 What’s wrong? Why does this program cause an error? What does INDENTATION do?

More Related