11
WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

Embed Size (px)

Citation preview

Page 1: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

WHAT IS THE VALUE OF X?

x = 0for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

Page 2: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

LMCLITTLE MAN COMPUTER

LESSON 3A

LET’S GO LOOP DE DO - LOOPING

Page 3: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

WHAT IS A LOOP?

Page 4: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

IF LMC CAN ONLY ADD OR SUBTRACT, HOW DO WE MULTIPLY?

• Loop! – share your ideas• Think about what multiply is really doing

Page 5: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

LET’S LOOK AT AN EXAMPLE

1. A number needs to be imputed

2. The number needs to be stored in a variable

3. The program needs to start a loop

4. Load the number that is stored

5. Add the number to it

6. Then store it

7. Then print it out

8. Then go back, (branch) to the start of the loop

Page 6: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

LOAD LMC AND CREATE A LOOP

1. A number needs to be imputed

2. The number needs to be stored in a variable

3. The program needs to start a loop

4. Load the number that is stored

5. Add the number to it

6. Then store it

7. Then print it out

8. Then go back, (branch) to the start of the loop

Page 7: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

COMPILER TOP TIPS

• ALWAYS SAVE THE FILE BEFORE RUNNING• ENSURE THE LMC IS RESET• ADD THE VARIABLES (DATA) TO THE END

Page 8: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

HINTS

• Create the variable at the bottom with DAT

• Create a loop by assigning a name instead of a numen,

• For example – start LDA number

Page 9: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

CAN YOU EDIT THE CODE SO THAT IT ADDS THE FIRST NUMBER EACH TIME?

Page 10: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

DID YOU GET THIS?

Page 11: WHAT IS THE VALUE OF X? x = 0 for value in [3, 41, 12, 9, 74, 15] : if value < 10 : x = x + value print x

THE HACK DEN

• Design an algorithm for a program which calculates and then prints out the first 5 values in the 8 times table.

• Test it• Research it• Create a compiler version• Keep a record of what you did in word or notepad