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