Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 3 Computer Programming Learning Objective:

Similar presentations


Presentation on theme: "Week 3 Computer Programming Learning Objective:"— Presentation transcript:

1 Week 3 Computer Programming Learning Objective:
Gray , Calibri 24 Dark Red RGB , Calibri 54 Learning Objective: To be able to use #Comments in your Code To understand what =variables are To be able to use = to assign variables

2 BUT 156 add 567 132 subtract 46 256 divided by 8 389 multiplied by 13
Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add subtract 46 256 divided by multiplied by 13 >>> print( ) 723 >>> print( ) 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 My_name = ‘Sydney’ We can also assign numbers >>> pizza = 250
Last week we learnt about variables and assignment. We learnt how to assign data (such as a word) to a variable! My_name = ‘Sydney’ A word is also known as a String [just a bunch of letters!] 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

4 Use the HASH key (#) after the line of code you want to comment
# 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… 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 Locate your Python program called InteractiveProgram.py and open it.
# 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 works We input our first number – 9
We then select the operator (the divide sign) Gray 80%

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

9 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 Internal Memory 9 / Gray 80%

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

11 Our calculator program
The program explained #red writing is useful comments numb1 and num2 variables which will be located memory Gray 80% The variable ans is assigned the sum ans = ans will be printed as 22 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 Gray 80%

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

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 48 No speech marks CLICK HERE FOR PLENARY


Download ppt "Week 3 Computer Programming Learning Objective:"

Similar presentations


Ads by Google