
Introduction to Python Programming with While Loops
"In this lesson, you will learn how to use the while loop in Python programming. Follow along as we introduce the while loop concept and teach you how to trace a program's execution step by step. Get ready to enhance your Python skills with practical examples and hands-on activities."
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? Draw on your sheet
Lesson objectives In this lesson we will introduce the while loop using Python You should learn to use a while loop in a Python program You will learn to trace a program to keep track of what it is doing
Variables Table counter = 1 while counter < 4: print("Happy days") What is printed? counter = counter + 1 print( End of program )
Variables Table Step 1: Draw round all expressions counter = 1 while counter < 4: print("Happy days") What is printed? counter = counter + 1 print( End of program )
Step 2: Draw arrows to show the order the statements are executed Variables Table counter = 1 FALSE while counter < 4: TRUE print("Happy days") What is printed? counter = counter + 1 print( End of program )
Step 3: Work through the program showing variables and output Variables Table counter counter = 1 FALSE while counter < 4: TRUE print("Happy days") What is printed? counter = counter + 1 print( End of program )
Step 3: Work through the program showing variables and output Variables Table counter counter = 1 while counter < 4: 1 FALSE TRUE print("Happy days") What is printed? counter = counter + 1 print( End of program )
Step 3: Work through the program showing variables and output Variables Table counter counter = 1 1 FALSE TRUE while counter < 4: 1 TRUE print("Happy days") What is printed? counter = counter + 1 print( End of program )
Step 3: Work through the program showing variables and output Variables Table counter counter counter = 1 1 1 FALSE while counter < 4: 2 TRUE print("Happy days") What is printed? counter = counter + 1 Happy days print( End of program ) Working out area counter = counter + 1 counter = 1 + 1 counter = 2
Step 3: Work through the program showing variables and output Variables Table counter = 1 counter 1 FALSE TRUE while counter < 4: 2 2 TRUE print("Happy days") What is printed? counter = counter + 1 Happy days print( End of program )
Step 3: Work through the program showing variables and output Variables Table counter counter counter = 1 1 1 FALSE while counter < 4: 2 TRUE 3 print("Happy days") What is printed? counter = counter + 1 Happy days print( End of program ) Happy days Working out area counter = counter + 1 counter = 2 + 1 counter = 3
Step 3: Work through the program showing variables and output Variables Table counter counter = 1 1 FALSE TRUE while counter < 4: 3 2 3 TRUE print("Happy days") What is printed? counter = counter + 1 Happy days print( End of program ) Happy days
Step 3: Work through the program showing variables and output Variables Table counter counter counter = 1 1 1 FALSE while counter < 4: 2 TRUE 3 print("Happy days") 4 What is printed? counter = counter + 1 Happy days print( End of program ) Happy days Happy days Working out area counter = counter + 1 counter = 3 + 1 counter = 4
Step 3: Work through the program showing variables and output Variables Table counter counter counter = 1 1 1 FALSE FALSE while counter < 4: 4 2 TRUE 3 print("Happy days") 4 What is printed? counter = counter + 1 Happy days Happy days print( End of program ) Happy days
Step 3: Work through the program showing variables and output Variables Table counter counter counter = 1 1 1 FALSE FALSE while counter < 4: 2 TRUE 3 print("Happy days") 4 What is printed? counter = counter + 1 Happy days print( End of program ) Happy days Happy days End of program
Variables Table def input_name(): name = input("What is your name? ") counter = 1 What is printed? (Output) while counter <= 4: print("Hello" + name) Working out area counter = counter + 1 print("Goodbye "+ name) Step 1: Draw round all expressions Step 2: Draw arrows showing the order in which the statements will be executed Step 3: Work through the program filling in the variables table and the Output box
PR I M M Tasks in pairs 25 minutes Now do the exercises on Activity Sheet 6c Download the file starter_activity_sheet_6.py
PR I M M Review Match the keyword to the piece of code 1 A. Iteration B. Selection 2 C. Sequence 3 Now write three more examples of sequence, selection and iteration in your books (use your previous programs to find examples).