A mini TRACS
Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) What is printed?
Step 1: Draw round all expressions Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) What is printed?
Step 2: Draw arrows to show the order the statements are executed Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) FALSE TRUE What is printed?
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter FALSE TRUE What is printed?
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter 1 FALSE TRUE What is printed?
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter 1 FALSE TRUE 1 TRUE What is printed?
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter counter 1 1 FALSE 2 TRUE What is printed? Happy days 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 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter 1 FALSE TRUE 2 2 TRUE What is printed? Happy days
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter counter 1 1 FALSE 2 TRUE 3 What is printed? Happy days 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 = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter 1 FALSE TRUE 3 2 TRUE 3 What is printed? Happy days Happy days
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter counter 1 1 FALSE 2 TRUE 3 4 What is printed? Happy days 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 = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter counter 1 1 FALSE FALSE 4 2 TRUE 3 4 What is printed? Happy days Happy days Happy days
Step 3: Work through the program showing variables and output Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) counter counter 1 1 FALSE FALSE 2 TRUE 3 4 What is printed? Happy days Happy days Happy days End of program
Now for another example
What is printed? (Output) Variables Table def input_name(): name = input("What is your name? ") counter = 1 while counter <= 4: print("Hello" + name) counter = counter + 1 print("Goodbye "+ name) What is printed? (Output) Working out area 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