1 / 39

Lesson 2

Lesson 2. Get Started with Python – Post-Installation – Use the GUI. Can I make a game now?. Not yet! B asic programming concepts must come first. These concepts are:. values, operators, expressions, and variables . . Peter Vesterbacka – Co-Creator of Angry Birds.

kenda
Télécharger la présentation

Lesson 2

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. Lesson 2 Get Started with Python – Post-Installation – Use the GUI

  2. Can I make a game now? • Not yet! • Basic programming concepts must come first. • These concepts are: values, operators, expressions, and variables.

  3. Peter Vesterbacka – Co-Creator of Angry Birds

  4. Angry Birds wasn’t developed in a day ….

  5. Everybody has to start • Somewhere 

  6. So let’s get Started With Python • Assuming you are working in Windows, you should be able to run Python by choosing: • Start, Programs, Python 3.1, IDLE (Python GUI).

  7. The Python Shell

  8. Printing things to the Screen in Python Print (‘Hello I wish to print this to the screen’)

  9. In computer science, the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language.  Correct Syntax Correct Syntax

  10. Doing rather basic Maths Things in the Shell Stuff like  2+2 = 4

  11. Using the Shell like a Calculator! Notice the space here didn’t make much of a difference Yeah – that can’t happen, even in Python.

  12. Math Operators in Python

  13. Expressions • Expressions are made up of values (the numbers) connected by operators (the math signs)

  14. Sounding Clever • When a computer solves the expression 3 + 5 and gets the value 8, if we want to sound clever we say it has evaluated the expression. • Evaluating an expression is basically reducnig the expression to a single value • So, don’t say: “1+1 is 2 duh!” …say “The expression1+1 evaluates to the value 2 ….”

  15. Creating a Chatbot!

  16. Step 1

  17. Step 2 Open a new Window !

  18. Step 3 Type this code in! If you’re lazy, cut and paste the below code. If you’re lazy, Cut and paste question = "What did you have for lunch?" print (question) answer = input() print ("You had " + answer + "! That sounds delicious!")

  19. Step 4 Click File – Save as. Save the file, and as long as it ends with .py It will work okay!

  20. Step 5 Run the program and test it to see if it works!

  21. CHALLENGE: THINK! Using the given code and analysing how it works, are you able to ask more questions and get more answers, and thus create your own chatbot? Be Creative!

  22. http://www.codecademy.com/ Click on “LEARN” Select Python! See what more you can learn!

  23. And back to Errors for a while…. Let’s look at the types of Errors in Programming and what they are -

  24. What was the last mistake you made? We all make mistakes …. Sometimes we say or do the wrong things…. Other times, our thinking (or logic) is flawed which leads to incorrect conclusions. And we all know that when we don’t follow good advice, bad things tend to happen. Mistakes are part of life …. But following instructions (or good laws) can help minimise them.

  25. In the human body, pain acts as a warning signal when something is wrong. • Put your hand in a flame and the pain will send a signal to your brain making you instantly pull away.

  26. In a disease called Leprosy, the patients cease to feel pain, so theirlimbs waste away and get damaged. • Warning signals are important! • In computing language we call this VALIDATION • Validation messages can pop us to tell us when we’ve made a mistake. Image: the hands of a leprosy victim

  27. Warning signals or helpful warnings to VALIDATE data in Computing • Validation = ensuring that all the data entered into the system is VALID • It doesn’t have to be “correct” but must be valid. Restricting options are a type of validation as the user is stopped from making a mistake!

  28. Errors in Programming • Types of Errors • Syntax Errors • Run Time errors • Logic Errors As a programmer – you may come across the above types of errors. They are errors of different types and are usually a result of mistakes that have been made. Mistakes or errors occur when someone hasn’t been careful to follow the RULES of the language they are using ….

  29. Syntax Error The following sentence: I green the monkey. Is grammatically wrong or has what we call a syntaxerror. "Green" is an adjective, not a verb. Errors like this (or even misspellings) can’t be understood. They are nonsense! Similarly, if you enter a VB statement that the compiler cannot understand, you have committed a syntax error.

  30. Run time Error Run time errors are detected while the program executes. They’re the ones that CRASH your program These are often discovered when the user enters illegal data. For example, if the user types in a string when the computer expects a number, there will be a runtime error. Runtime errorscan be tricky to track down. These errors occur when the programme is running. A simple way to crash a programme is to try to divide by zero!

  31. Logic Error Syntax errors are errors of grammar; whereas, logical or semantic errors are errors of meaning. These can be thought of as coding errors. Coding errors that YOU make. They can be quite difficult to track down, and have you pretty annoyed. You will often hear yourself saying “It should work! Why won't it?!?!"

  32. What type of Error? SYNTAX

  33. What type of Error? LOGIC Example Source: http://www.homeandlearn.co.uk

  34. What type of Error? RUNTIME Example Source: http://www.homeandlearn.co.uk

  35. Heard of Ludwig Wittgenstein? The TractatusLogico-Philosophicus • In the Tractatus, Wittgenstein attempts to acquire an understanding of how language works. He believes that before we attempt to solve the problems of philosophy, we must first understand our use of language, and how it relates to the world we observe Considered among the greatest philosophers of the century. He studied the problems and limitations of language!

  36. A lot of Great Computer Scientists … • …were also Great Philosophers • Take the Great CHARLES BABBAGE (inventor of the first analytical engine) • He pontificated a lot about the nature of the universe • In some writings, he wrote of “God” as the supreme programmer – and suggested the world we live in may just be a program!

  37. We’ll be looking at Variables (how to implement these in Python) next …

  38. End of Lesson 2

More Related