Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming In Lesson 3.

Similar presentations


Presentation on theme: "Programming In Lesson 3."— Presentation transcript:

1 Programming In Lesson 3

2 Recap Complete the starter activity

3 Objectives Outcomes Understand the benefits of a function
Be able to write and call a function Understand how and why we should use comments in our code Outcomes All-Level 4 To be able to write a function - with help be able to add comments to your code Most-Level 5 Be able to write a these with little help. Some-Level 6 Independently write these and adapt them and complete one of the extension tasks.

4 Recap - variables Write the statements that ask the user for their name and a number and display them using this line of code print(user + " your number is " + number) Hint: Use the input() function.

5 Recap-input Did you get something like… print("Enter your name")
user=input() print ("Enter your number") number=input() print(user + " your number is " + number)

6 Functions In the context of programming, a function is a named sequence of statements that performs a desired operation. You have already used several functions, who can name one? input print int randint This operation is specified in a function definition. In Python, the syntax for a function definition is:

7 Calling a Function Functions allow us to split our coding problem into smaller chunks – which make it easier to understand They can be reused – the print function for example Allows many people to work on the same project at once Allows a project to be tested as each part is completed. Lets make our function The process for this is File , New. In this new window you will need to create a function. Demonstarte example.

8 Out First function Lets go through this. def main (): print ("Hello")
The syntax of a function. Main is the name of the function that you call in your program. def main (): print ("Hello") main() Lets go through this. In your program – this is how you call the function called main.

9 Task 1 – Name function Write a Function that will ask your name, and print it out. You have 5 minutes to complete this task. Extension: Expand it by getting the user to enter a number that you will multiply by your age, add the day of the month and display it.

10 Answer Update your self assessment in Lesson 3 section – Task 1 – Name function.

11 Comments Commenting is very very very important in coding.
It describes what is going on The idea is for someone who has never seen the code to be able to read it, understand it and change it It acts as a reminder, when you go back and look at your code. #

12 Comments - Standard Every 2 lines of code NEEDS a comment

13 Task 2 – Numbers function
Write a program that will ask the user for four integer numbers and then add these numbers together before displaying the answer Remember I am looking for comments in your work. Demonstrate on board

14 Answer Update your self assessment in Lesson 3, Task 2 – Numbers function.

15 Plenary

16 Fun Time Try the fractal creating python programs.
In your lesson 3 folder – under fractals.


Download ppt "Programming In Lesson 3."

Similar presentations


Ads by Google