Skip to content

Latest commit

 

History

History
62 lines (37 loc) · 2.23 KB

DRAFT 06 Next steps with Python.md

File metadata and controls

62 lines (37 loc) · 2.23 KB
Title Teaching Exercises Question Objectives Activity Keypoints
Next steps with Python
15
1
Can you handle a little bit of coding for a quick result?
Use Python to perform basic computation
With a group, have a go at changing some of the code learnt in this module to produce different results.
Get excited, you can do it! Coding is just language.

Ready to splash a little with Python?

Using the workshop list of commands - saved in the repository as Worksheet_Python.txt we can now start with some basic coding.

  • First let's start with some maths.

    • In a new cell, select 'code'. Remember that the code cell looks different to the markdown cell. How can you tell? Type the following inside the cell:

      list(range(1, 20))

    • Click on 'Run' or use the shortcut Shift+Enter to execute the cell.

    • You have created a list of the range of numbers from 1 to 20. Woohoo!

    • In the next cell type the following:

      a = list(range(1, 20))

    • Click on 'Run' or use the shortcut Shift+Enter to execute the cell.

    • This cell tells the computer that the list of numbers you created can now be called 'a'. This is called a 'value'.

    • In the next cell type the following:

      x = sum(a)

    • Click on 'Run' or use the shortcut Shift+Enter to execute the cell.

    • This second instruction tells the computer to add each of those numbers in the list ('a') together and give that total a value of 'x'.

    • Now type the following in the next cell:

      print(x)

  • Click on 'Run' or use the shortcut Shift+Enter to execute the cell.

  • This last instruction tells the computer to print the total of the list of numbers on the screen.

You just did some computing! Hooray! With these three instructions you have performed a 'sequence'. This is a list of instructions to be carried out in order and forms one of the backbones of programming.

Mini-activity

Take a few minutes to change the range of numbers, and/or change the values and see what happens. Have a bit of fun with it - see if you can beat the computer with your amazing mental arithmetic skills. Or just be amazed at how fast it can be.

Alt Text