Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add 567132.

Similar presentations


Presentation on theme: "COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add 567132."— Presentation transcript:

1 COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3

2 Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add 567132 subtract 46 256 divided by 8389 multiplied by 13 >>> print(156 + 567) 723 >>> print(132 - 46) 86 >>> print(256 / 8) 32.0 >>> print(389 * 13) 5057 In computing, the mathematical operators are as you’d expect them to be: Add is + Subtract is – BUT Divide is / Multiply is * (asterisk Shift + 8)

3 Last week we learnt about variables and assignment. We learnt how to assign data (such as a word) to a variable! My_name = ‘Sydney’ We can also assign numbers >>> pizza = 250 >>> coke = 100 >>> chips = 150 Some interesting expressions can then be evaluated such as: >>> pizza + chips 400 >>> 2 * pizza 500 A word is also known as a String [just a bunch of letters!]

4 # Comment Your Code Comments are often added to computer programs to allow people to understand the intentions of the person who created the code. The Python interpreter ignores the comments completely, so syntax is not a problem. In practise, it is not necessary to comment every line/section – only where it is not obvious what is going on. Use the HASH key (#) after the line of code you want to comment Look at how comments have been used in the program below…

5 # Commenting On Your Code Consider these 3 questions… 1.How could you add some information about the program, creator, date etc.? Answer- add a top line comment with name, date etc. 2. Is it necessary to comment on every single line? Answer- Only comment when it is not clear to another person 3. If the interpreter ignores everything after the #, how else could this be useful? [harder question] Answer- You can use # to ‘comment out’ sections of code that are not working to help with debugging.

6 # Comment Your Code Locate your Python program called InteractiveProgram.py and open it. Use comments to add… your name and date [at the top] The purpose of the program [on the second line] Meaning to any line of code so it makes sense to someone else reading it. line of code you wan # # # # # # # # # #

7 How a calculator worksworks We input our first number – 9 We then select the operator (the divide sign)

8 How a calculator works When we input our second number 4, nine disappears along with the operator divide. They are placed into memory Internal Memory 9 /

9 Internal Memory How a calculator works The equals sign will return both the 9 and the operator in order to work out the answer and return it to screen 9 /

10 Our calculator program Our calculator program will add up two numbers and then return the answer to the screen

11 Our calculator program The program explained ans will be printed as 22 #red writing is useful comments numb1 and num2 variables which will be located memory The variable ans is assigned the sum ans = 14 + 8 22

12 Running our Python program The star is telling us we have not saved the program Save it as adding.py. Push F5 on the keyboard to run

13 What Language are we using? Describe a variable? What does this = mean? sound Python A temporary value in memory Assign to x = x + 1

14 Name a function we had used? What are letters known as in programming? x = input(Enter name) Where is the error here? print() or input() A string No speech marks


Download ppt "COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add 567132."

Similar presentations


Ads by Google