
Python Programming Lesson: While Loops and If Statements
In this Python programming lesson, you will practice implementing while loops and if statements in larger programs. The focus is on making programs more user-friendly and dynamically adding to string variables. Additionally, some learners will experiment with generating random numbers in their programs.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Python Programming January 2018 Lesson 1 of 10
PR I M M Do Now in Pairs What does this code do?
Lesson objectives In this lesson you will practise more while loops in bigger programs You will be able to add an if statement to make a program with a while loop a bit more user friendly You will be able to keep adding to a string variable while the program is running Some of you will be able to use a random function to generate a random number in a program
PR I M M Questions 15 minutes In pairs answer the questions on Activity Sheet 7 Download the starter program at starter_activity_sheet_7
Answers 1. What happens if you don t add any toppings? 2. Fill in the table 3. Why do you need a while loop? 4. What would happen if you didn t have the line next_topping = " ? What would happen if you didn t have the line toppings = "" ? next_topping toppings and pineapple olives mushrooms 5. What does this line do? 6. How would you like to improve this program?
PR I M M Tasks in pairs 20 mins Now do the programming exercises in pairs from the sheet (Task 4) 1. Improve the pizza program so that it doesn t print out and X at the end. You will have to add an if statement to do this. 2. Write a version of the game I went shopping and .. . Then try it on somebody who can t see the computer to see if they can remember everything the computer has stored from the shopping game? The game should stop when the user presses the enter key rather than adding another item. . etc. There are extension exercises if you finish
Review 10 mins In the last few lessons you have learned about if statements, for loops and while loops these are the most useful and important elements of any programming language. Imagine you are writing a letter to somebody in the year below who is just starting to learn programming write down 5 tips you would give them, eg. What sometimes goes wrong? How can you fix it? How can you get better at programming? What do you do if you get stuck?