Lesson Aims:
- Learn how to convert between algorithms and python code and vice-versa
- Practice conditionals, if, elif, else
In this lesson you will look at Algorithms and how they can be used to represent the structure of a program. You will also work backwards and create an algorithmic diagram for a given program.
1. Starter: Load Python and create a program that asks the user for two numbers and then subtracts the first number and prints the answer.
HINT: x = input("please enter number"), print " ", more help click here
HINT: x = input("please enter number"), print " ", more help click here
2. Remember IF statements?:
IF, ELIF, ELSE? Look at the algorithm on the left, can you write a Python program which represent this diagram? Think about what it is doing, discuss your ideas, check you answer with other students and make improvements to your program. Use the internet to support your research and development |
3. Code to Diagram:
Look at the Python code on the right,can you work out what is does? Try it in IDLE, did it do what you thought it would? Now create a algorithm diagram which represents the code. Check your answer when you are finished. |
|
4. Now let's do the reverse - look at the algorithm diagram on the right, can you work out what it does? Can you solve it? Check with someone else. Now create the program in Python - the answer is opposite, only check when complete.
|
|