Practical 2#

Further programming in Python#

Aim#

The aim of this practical is to build upon the Python syntax and concepts we learn in Practical 1 and explore further programming concepts and Python functionality.

Objectives#

During this practical you will learn how to:

  • create your own functions

  • use NumPy arrays and perform different operations with them

  • start plotting with Matplotlib

Instructions#

The best way to do this practical is to read the associated notes which will introduce you to the core concepts of Python programming. These notes are designed with all the details you would need to be able to perform the exercises in this practical. In general, you would not need to refer to additional texts and resources as these notes have been explained in detail with accompanying visual aids and examples to explain concepts to beginners. Apart from the exercises listed below, there are also examples throughout the notes which provide insight on the concepts introduced, and therefore, it is recommended that you also run these examples as you progress through the practical notes.

If you are an experienced Python programmer, you might find that you already know about the content in these notes. You may want to skip sections of notes that you already know and attempt the exercises that are at the higher levels.

Exercises levels#

Exercises in this practical are labelled with the level of difficulty of the respective exercise:

Level

Description

Level 1: Excercises in Level 1 are simple excersises designed to get you familiar with the Python syntax. If you already know how to program in Python, you may skip these exercises.

Level 2: Excercises in Level 2 combine different Python programming concepts to solve simple problems.

Level 3: Exercises in Level 3 test not just the understanding of the Python syntax but also how Python can be used to solve problems.

Exercises#

This practical is composed of the following exercises:

Exercise

Description

Level

Exercise 2.1

Creating functions: In this exercise, we explore creating functions.

Exercise 2.2

Fibonacci sequence function: In this exercise, we will rewrite the code we attempted in Exercise 1.15 into a function.

Exercise 2.3

Creating NumPy arrays: In this exercise, we explore creating NumPy arrays.

Exercise 2.4

dtype of NumPy arrays: In this exercise, we look into the way NumPy allocated dtypes to arrays.

Exercise 2.5

NumPy array manipulations: This exercises performs different NumPy array manipulations.

Exercise 2.6

Numpy views and copies: This exercise explores NumPy array views and copies.

Exercise 2.7

Odd and even numbers with NumPy arrays: In this exercise we identify odd and even numbers using NumPy arrays.

Exercise 2.8

Mathematical formulas: In this exercise, we will use NumPy to work with mathematical formulas.

Exercise 2.9

Random numbers: This exercise explores gerenating random numbers.

Exercise 2.10

Line plot: This exercise introduces you to plotting with matplotlib.

Exercise 2.11

Scatter plot: This exercise draws a scatter plot from random numbers.

Managed to solve all the exercises? Well done!

In the programming world, many organisations award badges to learners on the acquisition of a new skill or completion of a milestone. If you attempted and solved all the exercises of this practical, you definitely deserve your first badge of this course.

_images/level-2-badge.png

Next week

In the next practical we will learn how to:

  • manipulate tabular data

  • visualise tabular data

Happy Python practicing!