1 / 18

Programming

Programming. In. Lesson 5. R ecap. Complete the starter activity. Objectives. Understand how to use looping statement (while) Understand to use the break statement Understand the development process of flow charts to comments to code Outcomes

minna
Download Presentation

Programming

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 In Lesson 5

  2. Recap • Complete the starter activity

  3. Objectives • Understand how to use looping statement (while) • Understand to use the break statement • Understand the development process of flow charts to comments to code Outcomes • All-Level 4 written code using while - with help developed programs using pseudo code • Most-Level 5 Be able to write a these with little help. • Some-Level 6 Independently write these and adapt them and complete the extension tasks.

  4. Loops • You might remember this code from your truth table of last lesson. It is part of the function that got the user input. • It uses a while statement to keep asking the user to input a value until it is one of the required values.

  5. While statement Don’t forget the full colon while expression : statement 1 statement 2 statement 3 Notice the indentation – this defines the statements that are in the while statement Statements are executed while the expression is true

  6. Write a loopy program – pseudo code start Write a program that asks the user for a number and counts down to 1 displaying each number as it goes. a=int(a) – converts number a to an integer You have the rest of the knowledge. Extension: Get you program to calculate the factorial of the number. Hint: factorial of 4 is 4 * 3 * 2 * 1. Ask user for a number • Write the pseudo code for the program. • We will then write the program comments from this pseudo code • We will then fill in the code for each comment. Convert to integer Is number > 0 No end Yes Display number Subtract one

  7. Write a loopy program - comments start Ask user for a number Convert to integer Is number > 0 No end Yes Display number Subtract one

  8. Write a loopy program - code • Extension: Get you program to calculate the factorial of the number. Hint: factorial of 4 is 4 * 3 * 2 * 1.

  9. Class discussion • With your classmate you have 2 mins to discuss… • What was most difficult in the program • What was most fun • What was the boring part

  10. While statement Break while expression : statement 1 statement 2 break Notice the indentation – this defines which statements are in the while statement Statements are executed while the expression is true This command quits from the while statement – even if the expression is still true.

  11. Guess the number – Version 2 • Remember this – guessing a random number….

  12. Guess the number – Version 2 • I want you to make it even better • Give the user 6 chances to guess the number - use while statement • Let them know if their guess is too high - if statement • Let them know if their guess is too low - if statement

  13. What do we need to Change

  14. Set guesses to zero Yes Guesses > 6 Exit from while loop You have previously written most of this program. All you need to do is write the new section No Add 1 to guesses User has a guess Guess < number Yes Tell user too low No Yes Guess > number Tell user too high No Guess = number Yes Exit from while loop No

  15. Set guesses to zero Yes Guesses > 6 Exit from while loop No Add 1 to guesses User has a guess Yes Guess < number Tell user too low No Yes Guess > number Tell user too high No Guess = number Yes Exit from while loop No

  16. Write the code

  17. Extensions • Make the random number range from 1 to 30 • Let them know the random number if they fail to guess it.

  18. Plenary • Complete the Lesson 5 plenary Quiz

More Related