Coding User - Vol 5 2023

Download as pdf or txt
Download as pdf or txt
You are on page 1of 118

NEW BUMPER 118 PAGE PYTHON SPECIAL EDITION!

%&!$!#%& &"%

 !%&%    

! &

$%&
  

  

 !% !! ! &


!! ! ! !!  ! ! ! 
 ! ! !  !  ! !

"!#&%#$&#"# "&"&$ "# "!&"!&%&%& %$


%  $&"%$% $&#%$& % !$  !%# $#&"%#

  
  

www.pclpublications.com
঍঩়লস঺ত঱ষষলযনত঵঱ষলদলধন॰ষফবশবশষফন঳সথযবদতষবল঱঩ল঵়লসॲছবষফনহন঵়
বশশসনলস঵ষনতরল঩ন঻঳ন঵ষশথ঵ব঱পশ়লসষফনথনশষষব঳শ॰ষ঵বদমশত঱ধষসষল঵বতযশ
঩ল঵দ঵নতষব঱পদলধন॰঵নপত঵ধযনশশল঩়লস঵যনহনযল঩ন঻঳ন঵বন঱দনॲ
঍঱ষফবশ঩ব঩ষফবশশসন঺নযললমতষষফনঔ়ষফল঱যত঱পসতপনত঱ধফল঺ষলপনষ
শষত঵ষনধ঺বষফবষত঱ধযনত঵঱বষশসশনশॲওস঵নতশ়ॱষলॱ঩লযযল঺ষসষল঵বতযশশফল঺
়লসফল঺ষলদ঵নতষনশলরনসষষন঵য়ন঳বদ঳঵লভনদষশ঺বষফঔ়ষফল঱ॲ঍঩বষ৅শত঳঳শ
ত঱ধপনত঵়লস৅঵নযললমব঱প঩ল঵॰লস঵ব঱ॱধন঳ষফ঵নহবন঺শফনয঳়লস঩ব঱ধষফন
হন঵়থনশষ়লস঵রল঱ন়দত঱থস়ॲছনদলহন঵তযযষফনহন঵়থনশষল঩ষনদফ
তদ঵লশশতযযরতভল঵঳যতষ঩ল঵রশ॰শল়লস৅঵নথলস঱ধষল঩ব঱ধশলরনষফব঱প
তরতঽব঱পॲছনযদলরনষলষফন঩ত঱ষতশষবদ঩ব঩ষফবশশসনল঩ইলধব঱পঙশন঵ॲ
ইল঱ষন঱ষশ

ॸॺ ছল঵মব঱প঺বষফচত঵বতথযনশ
ॺ ঋনষষব঱পগষত঵ষনধ঺বষফঔ়ষফল঱ ॸॼ ঙশন঵঍঱঳সষ
ॼ আনব঱পতঔ঵লপ঵তররন঵ ॹॴ ই঵নতষব঱পঊস঱দষবল঱শ
ॵॴ অআ঵বন঩ঌবশষল঵়ল঩ইলধব঱প ॹॶ ইল঱ধবষবল঱শত঱ধঐলল঳শ
ॵॶ ছফতষদত঱ঝলসঈল঺বষফঔ়ষফল঱ঃ ॹॸ ঔ়ষফল঱঑লধসযনশ
ॵॸ ঔ়ষফল঱ব঱঒সরথন঵শ ॹॺ ঔ়ষফল঱উ঵঵ল঵শ
ॵॺ ছফ়ঔ়ষফল঱ঃ ॹॼ ইলরথব঱ব঱পছফতষঝলসএ঱ল঺গলঊত঵
ॵॼ ঔ়ষফল঱ল঱ষফনঔব ॺॴ ঔ়ষফল঱ব঱ঊলদসশॾগষবষদফব঱পআযতদমঌলযনশ
ॶॴ ঙশব঱পচব঵ষসতয঑তদফব঱নশ
ॶॶ ই঵নতষব঱পতইলধব঱পঔযতষ঩ল঵র ॺॶ ছল঵মব঱প঺বষফঈতষত
ॺॸ ঐবশষশ
ॶॸ ঌনযযলছল঵যধ ॺॺ ঘস঳যনশ
ॶॺ উ঴সব঳রন঱ষঝলসছবযয঒ননধ ॺॼ ঈবদষবল঱ত঵বনশ
ॶॼ ঋনষষব঱পষলএ঱ল঺ঔ়ষফল঱ ॻॴ গ঳যবষষব঱পত঱ধ঎লব঱ব঱পগষ঵ব঱পশ
ॷॴ ঌল঺ষলগনষঙ঳ঔ়ষফল঱ব঱ছব঱ধল঺শ ॻॶ ঊল঵রতষষব঱পগষ঵ব঱পশ
ॷॶ ঌল঺ষলগনষঙ঳ঔ়ষফল঱ব঱ঐব঱স঻ ॻॸ ঈতষনত঱ধঘবরন
ॷॸ গষত঵ষব঱পঔ়ষফল঱঩ল঵ষফনঊব঵শষঘবরন ॻॺ ও঳ন঱ব঱পঊবযনশ
ॷॺ ঝলস঵ঊব঵শষইলধন ॻॼ ছ঵বষব঱পষলঊবযনশ
ॷॼ গতহব঱পত঱ধউ঻নদসষব঱পঝলস঵ইলধন ॼॴ উ঻দন঳ষবল঱শ
ॸॴ উ঻নদসষব঱পইলধন঩঵লরষফনইলররত঱ধঐব঱ন ॼॶ ঔ়ষফল঱ঋ঵ত঳ফবদশ
ॸॶ ঒সরথন঵শত঱ধউ঻঳঵নশশবল঱শ ॼॸ ইলরথব঱ব঱পছফতষঝলসএ঱ল঺গলঊত঵
ॸॸ ঙশব঱পইলররন঱ষশ ॼॺ ঔ়ষফল঱ব঱ঊলদসশॾঋতরব঱প

4 | www.pclpublications.com
e Not that long ago a black hole was just a collection of theories
PDVV and mathematics written down on paper, speculated only by the
e EULJKWHVWPLQGVRIRXUWLPH+RZHYHUDVZLWKPRVWWKLQJVVFLHQWLƬF
zon. our understanding of the universe and our abilities to read it have
DQG greatly improved and, with the culmination of years of
tures hard work by a collaboration of observatories,
eal VFLHQWLVWVDQGHQJLQHHUVZHJRWRXUƬUVW
U\ image of a black hole.

night
f
e)
e ॼॼ খউচ঍উছগ
ures
60 ॽॴ গঘ঑ইফত঵পনঘ঵ননগ঺ব঱পইফত঵পব঱পগষতষবল঱
nds
ॽॶ ঎লথ়ঋ঵ব঳ঘবপফষঋল঵বযযতঔলধ঩ল঵঑তপগত঩ন
ॽॷ ঈনহলযল঑তপবদॶছবঊবॺছফলযনঌলরনছবॱঊবএবষ
es,
ॽॸ গত঱ঈবশমবজ঳ত঱ধঊযতশফঈ঵বহনঐস঻নॶॹॺঋআ
he
ॽॸ এন঱শব঱পষল঱গষসধবলঈলদমইফত঵পব঱পগষত঱ধ
ॽॹ ঑঍঒঍জ঒উওঔॵॷॱঔল঵ষঋত঒ইফত঵পন঵
hat
lar ॽॺ ঘ঺নযহনগলসষফঔল঺ন঵ঔবদইফত঵পব঱পগষত঱ধ
o,
ॽॻ ঊখ঍ঘঞ॥খন঳নতষন঵ॺॴॴॴছবঊবউ঻ষন঱ধন঵
ॽॼ অব঵঳সযশনঔॵॴॴজগষন঵নলগ঳নতমন঵
ay. ॵॴॴ ঔ঵লদ঵নতষনঔলদমনষ
to ॵॴॶ গ঳যবদনॱচবধনলউধবষল঵४঑তমন঵
s.
area ॵॴॵ ঞলরথবনশ॰খস঱॥
g
ॵॴॸ খতধবলঋত঵ধন঱
ॵॴॹ ব঑তঽব঱পॶ
ॵॴॺ ঍র঳঵নশশবহনবওগঔফলষলপ঵ত঳ফ়অ঳঳শ
ॵॴॼ অযবন঱ॾ঍শলযতষবল঱
ॵॵॴ ঈলসথযনঈ঵তপল঱ঘ঵বযলপ়
ॵॵॵ অ঱লষফন঵ছল঵যধॱॶॴষফ
ॵॵॶ ঋ঵ত঱ধঘফন঩ষঅসষলঐবথন঵ষ়ইবষ়গষল঵বনশ
ॵॵॸ ঘন঱পতব
ॵॵॹ আঅঈঐঅ঒ঈ॰ঋতরনল঩ষফনঝনত঵উধবষবল঱

ॵॵॻ ঒ন঻ষ঑ল঱ষফ

www.pclpublications.com | 5
Getting Started

6
6 | ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
RQVFRP
ZZZSFOSXEOLFDWL
Getting Started

Python is a high-level, general-purpose programming language that


was developed by Guido van Rossum in the late eighties and is based
upon a number of other languages, while being the successor to the
popular ABC language.
It has been devised to work on a human level, so it’s readable and
understandable without needing to delve into obscure volumes of
machine code, hexadecimal characters, or even ones and zeros. It’s
clear, logical, comprehensive, powerful and functional, yet also easy to
follow and learn.
<RXZLOOILQG3\WKRQDWWKHKHDUWRIVRPHRIWKHPRVWinteresting and
cutting-edge technologies in the world. It’s the code that binds
supercomputer algorithms together; it’s used in the space industry, and
in science and engineering. AI, and the likes of Alexa and Siri, Cortana
and the Google Assistant all utilise Python for their powerful voice
recognition technology. It’s simply an amazing, versatile and incredible
language to learn.
So let’s get started and explore what you need to become a
Python programmer.


¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬ | 7
ZZZSFOSXEOLFDWLRQVFRP
Getting Started

Being a Programmer
Programmer, developer, coder, they’re all titles for the same occupation, someone who
creates code. What they’re creating the code for can be anything from a video game
to a critical element on-board the International Space Station. How do you become a
programmer though?

8 | 8 ZZZSFOSXEOLFDWLRQVFRP
Being a Programmer

MORE THAN CODE


For those of you old enough to remember the ‘80s, the golden era of home
FRPSXWLQJWKHZRUOGRIFRPSXWLQJZDVDYHU\GLƪHUHQWVFHQHWRKRZLWLV
today. 8-bit computers that you could purchase as a whole, as opposed to
EHLQJLQNLWIRUPDQG\RXKDYLQJWRVROGHUWKHSDUWVWRJHWKHUZHUHWKHVWXƪ
of dreams; and getting your hands on one was sheer bliss contained within
a large plastic box. However, it wasn’t so much the new technology that
FRPSXWHUVWKHQRƪHUHGPRUHRYHULWZDVWKHIDFWWKDWIRUWKHƬUVWWLPH
ever, you could control what was being viewed on the ‘television’.

Instead of simply playing one of the thousands of games available at the


Times have changed since programming in the ‘80s, time, many users decided they wanted to create their own content, their
but the core values still remain. own games; or simply something that could help them with their homework
RUKRPHƬQDQFHV7KHVLPSOLFLW\RIWKHELWKRPHFRPSXWHUPHDQWWKDW

“It’s up to you
creating something from a few lines of BASIC code was achievable and so
WKHƬUVWJHQHUDWLRQRIKRPHEUHGSURJUDPPHUZDVERUQ

how far to take


From that point on, programming expanded exponentially. It wasn’t long
before the bedroom coder was a thing of the past and huge teams of
designers, coders, artists and musicians were involved in making a single

your coding
JDPH7KLVRIFRXUVHOHGWRWKHSURJUDPPHUEHFRPLQJPRUHWKDQVLPSO\
someone who could fashion a sprite on the screen and make it move at the
press of a key.

adventure!” Naturally, time has moved on and with it the technology that we use.
However, the fundamentals of programming remain the same; but what
exactly does it take to be a programmer?

7KHVLQJOHPRVWFRPPRQWUDLWRIDQ\SURJUDPPHUUHJDUGOHVVRIZKDW
they’re doing, is the ability to see a logical pattern. By this we mean
VRPHRQHZKRFDQORJLFDOO\IROORZVRPHWKLQJIURPVWDUWWRƬQLVKDQG
envisage the intended outcome. While you may not feel you’re such a
person, it is possible to train your brain into this way of thinking. Yes, it
takes time but once you start to think in this particular way you will be able
to construct and follow code.

Second to logic is an understanding of mathematics. You don’t have to be


at a genius level but you do need to understand the rudiments of maths.
Maths is all about being able to solve a problem and code mostly falls under
the umbrella of mathematics.

%HLQJDEOHWRVHHWKHELJSLFWXUHLVFHUWDLQO\EHQHƬFLDOIRUWKHPRGHUQ
programmer. Undoubtedly, as a programmer, you will be part of a team
of other programmers, and more than likely part of an even bigger team
RIGHVLJQHUVDOORIZKRPDUHFUHDWLQJDƬQDOSURGXFW:KLOH\RXPD\RQO\
EHH[SHFWHGWRFUHDWHDVPDOOHOHPHQWRIWKDWƬQDOSURGXFWEHLQJDEOHWR
understand what everyone else is doing will help you create something
that’s ultimately better than simply being locked in your own coding cubicle.

Finally, there’s also a level of creativity needed to be a good programmer.


Again though, you don’t need to be a creative genius, just have the
imagination to be able to see the end product and how the user will interact
with it.

7KHUHLVRIFRXUVHDORWPRUHLQYROYHGLQEHLQJDSURJUDPPHULQFOXGLQJ
learning the actual code itself. However, with time, patience and the
determination to learn, anyone can become a programmer. Whether
Being able to follow a logical pattern and you want to be part of a triple-A video game team or simply create an
see an end result is one of the most valued automated routine to make your computing life easier, it’s up to you how
skills of a programmer. far to take your coding adventure!

ZZZSFOSXEOLFDWLRQVFRP 9 9
Getting Started

A Brief History of Coding


It’s easy to think that programming a machine to automate a process, or calculate a value,
LVDPRGHUQFRQFHSWWKDWoVRQO\UHDOO\KDSSHQHGLQWKHODVWƬIW\\HDUVRUVR+RZHYHUWKDW
assumption is quite wrong, coding has actually been around for quite some time.

01000011 01101111 01100100 01101001 01101110 01100111


(VVHQWLDOO\DOOIRUPVRIFRGLQJDUHPDGHXSRIRQHVDQG]HURVRQRURƪVWDWHV7KLVZRUNV
for both a modern computer and even the oldest known computational device.

~87 BC a$' 1800 Ǖ Ǖ

,WoVGLƯFXOWWRSLQSRLQWDQH[DFW
start of when humans began to
‘program’ a device. However,
it’s widely accepted that the
Antikythera Mechanism is possibly
WKHƬUVWnFRGHGoDUWHIDFW,WoV Joseph Marie Jacquard invents a
dated to about 87 BC and is an programmable loom, which used cards with
ancient Greek analogue computer punched holes to create the textile design.
and orrery used to predict However, it is thought that he based his
astronomical positions. design on a previous automated weaving
process from 1725, by Basile Bouchon.

Ada Lovelace translated


the memoirs of the Italian
mathematician, Francis
Maneclang, regarding
Charles Babbage’s
Analytical Engine. She
made copious notes within
her writing, detailing a
7KH%DQŅ0ŅVÜEURWKHUVWKUHH3HUVLDQ
method of calculating
scholars who worked in the House of
Bernoulli Numbers
Wisdom in Baghdad, published the
XVLQJWKHHQJLQH7KLVLV
Book of Ingenious Devices in around
UHFRJQLVHGDVWKHƬUVW
850 AD. Among the inventions listed
computer program. Not
was a mechanical musical instrument:
bad, considering there
a hydro-powered organ that played
were no computers
interchangeable cylinders automatically.
available at the time.

RQVFRP
¬¬¬ ww
A Brief History of Coding

During the Second World From the 1970s, the development of the likes of C, SQL, C with
:DUVLJQLƬFDQWDGYDQFHV &ODVVHV & 0$7/$%&RPPRQ/LVSDQGPRUHFDPHWRWKH
were made in programmable IRUH7KHnVZDVXQGRXEWHGO\WKHJROGHQDJHRIWKHKRPH
machines. Most notably, the computer, a time when silicon processors were cheap enough for
cryptographic machines used RUGLQDU\IRONWREX\7KLVOHGWRDERRPLQKRPHEHGURRPFRGHUV
to decipher military codes with the rise of 8-bit machines.
XVHGE\WKH1D]LV7KH(QLJPD
was invented by the German
engineer Arthur Scherbius,
but was made famous by Alan
7XULQJDW%OHWFKOH\3DUNoV
codebreaking centre.

Ǖ  Ǖ Ǖ 1990s-Present Day

Computer programming
was mainly utilised by
universities, the military and
big corporations during the ‘60s
and the ‘70s. A notable step
toward a more user-friendly,
or home user, language was
the development of BASIC
(Beginners All-purpose
Symbolic Instruction Code) in
the mid-sixties.

7KH,QWHUQHWDJHEURXJKWDZHDOWKRIQHZ
programming languages and allowed
people access to the tools and knowledge
needed to learn coding in a better way.
Not only could a user learn how to code,
they could also freely share their code and
source other code to improve their own.

7KHƬUVWWUXHFRPSXWHUFRGHZDV
Assembly Language (ASM) or
Regional Assembly Language. ASM Admiral Grace Hopper was part of
ZDVVSHFLƬFWRWKHDUFKLWHFWXUH the team that developed the UNIVAC
of the machine on which it was I computer and she eventually
being used. In 1951, programming developed a compiler for it. In time,
languages fell under the generic the compiler she developed became
term Autocode. Soon languages COBOL (Common Business-oriented
VXFKDV,3/)2575$1DQG$/*2/ Language), a computer language that’s
58 were developed. still in use today.

| 11
Getting Started

What can You


Do with Python?
Python is an open-source, object-oriented programming language that’s simple
to understand and write, yet also powerful and extremely malleable. It’s these
characteristics that help make it such an important language to learn.

Python’s ability to create highly readable code within a small set ƬQGORWVRIH[DPSOHVRIWKLVZKHUH3\WKRQLVDFWLQJEHKLQGWKH
of instructions has a considerable impact on our modern digital VFHQHV7KLVLVZK\LWoVVXFKDQLPSRUWDQWODQJXDJHWROHDUQ
ZRUOG)URPWKHLGHDOƬUVWSURJUDPPHUVoFKRLFHWRLWVDELOLW\WR
FUHDWHLQWHUDFWLYHVWRULHVDQGJDPHVIURPVFLHQWLƬFDSSOLFDWLRQVWR
DUWLƬFLDO,QWHOOLJHQFHDQGZHEEDVHGDSSOLFDWLRQVWKHRQO\OLPLWWR
Python is the imagination of the person coding in it.

It’s Python’s malleable design that makes it an ideal language for


PDQ\GLƪHUHQWVLWXDWLRQVDQGUROHV(YHQFHUWDLQDVSHFWVRIWKH
FRGLQJZRUOGWKDWUHTXLUHPRUHHƯFLHQWFRGHVWLOOXVH3\WKRQ
For example, NASA utilises Python both as a stand-alone language
DQGDVDEULGJHEHWZHHQRWKHUSURJUDPPLQJODQJXDJHV7KLVZD\
NASA scientists and engineers are able to get to the data they
need without having to cross multiple language barriers; Python
ƬOOVWKHJDSVDQGSURYLGHVWKHPHDQVWRJHWWKHMREGRQH<RXoOO

BIG DATA
Big data is a buzzword you’re likely to have come across in the last couple of years.
Basically, it means extremely large data sets that are available for analysis to reveal
patterns, trends and interactions between humans, society and technology. Of course,
it’s not just limited to those areas, big data is currently being used in a variety of
industries, from social media to health and welfare, engineering to space exploration
and beyond.

Python plays a substantial role in the world of big data. It’s extensively used to analyse
KXJHFKXQNVRIWKHDYDLODEOHELJGDWDDQGH[WUDFWVSHFLƬFLQIRUPDWLRQEDVHGRQ
ZKDWWKHXVHUFRPSDQ\UHTXLUHVIURPWKHZHDOWKRIQXPEHUVSUHVHQW7KDQNVWRDQ
impressive set of data processing libraries, Python makes the act of getting to the data,
in amongst the numbers, that counts and presenting it in a fashion that’s readable and
useable for humans.

7KHUHDUHFRXQWOHVVOLEUDULHVDQGIUHHO\DYDLODEOHPRGXOHVWKDWHQDEOHIDVWVHFXUHDQG
more importantly, accurate processing of data from the likes of supercomputing clusters.
For example, CERN uses a custom Python module to help analyse the 600 million
FROOLVLRQVSHUVHFRQGWKDWWKH/DUJH+DGURQ&ROOLGHU /+& SURGXFHV$GLƪHUHQWODQJXDJH
handles the raw data, but Python is present to help sift through the data so scientists
can get to the content they want without the need to learn a far more complex
programming language.

12 12
| ZZZSFOSXEOLFDWLRQVFRP
What can You Do with Python?

ARTIFICIAL INTELLIGENCE
$UWLƬFLDO,QWHOOLJHQFHDQG0DFKLQH/HDUQLQJDUHWZRRIWKH
most groundbreaking aspects of modern computing. AI is the
umbrella term used for any computing process wherein the
machine is doing something intelligent, working and reacting
in similar ways to humans. Machine Learning is a subset of AI
and provides the overall AI system with the ability to learn
from its experiences.

However, AI isn’t simply the creation of autonomous robots


intent on wiping out human civilisation. Indeed, AI can be
found in a variety of day-to-day computing applications where
the ‘machine’, or more accurately the code, needs to learn
from the actions of some form of input and anticipate what
the input is likely to require, or do, next.

7KLVPRGHOFDQEHDSSOLHGWR)DFHERRN*RRJOH7ZLWWHU
Instagram and so on. Have you ever looked up a celebrity on
Instagram and then discovered that your searches within other
VRFLDOPHGLDSODWIRUPVDUHQRZVSHFLƬFDOO\WDUJHWHGWRZDUG
VLPLODUFHOHEULWLHV"7KLVLVDSULPHH[DPSOHRIXVLQJ$,LQ
targeted advertising and behind the code and algorithms that
predict what you’re looking for, is Python. GAMING
Spotify, for example, uses Python based code, among $OWKRXJK\RXZRQoWƬQGWRRPDQ\WULSOH$UDWHGJDPHVFRGHGXVLQJ
other things, to analyse your musical habits and 3\WKRQ\RXPD\EHVXUSULVHGWROHDUQWKDW3\WKRQLVXVHGDVDQ
RƪHUSOD\OLVWVEDVHGRQZKDW\RXoYHOLVWHQHGWR H[WUDRQPDQ\RIWKHKLJKUDQNLQJPRGHUQJDPHV
LQWKHSDVW,WoVDOOFOHYHUVWXƪDQGPRYLQJ
forward, Python is at the forefront of the way 7KHPDLQXVHRI3\WKRQLQJDPLQJFRPHVLQWKHIRUPRIVFULSWLQJ
the Internet will work in the future. ZKHUHD3\WKRQVFULSWFDQDGGFXVWRPLVDWLRQVWRWKHFRUHJDPH
HQJLQH0DQ\PDSHGLWRUVDUH3\WKRQFRPSDWLEOHDQG\RXZLOODOVR
FRPHDFURVVLWLI\RXEXLOGDQ\PRGVIRUJDPHVVXFKDV7KH6LPV

$ORWRIWKHRQOLQH00253* 0DVVLYHO\0XOWLSOD\HU2QOLQH5ROH
WEB DEVELOPMENT 3OD\LQJ*DPH JDPHVDYDLODEOHXWLOLVH3\WKRQDVDFRPSDQLRQ
ODQJXDJHIRUWKHVHUYHUVLGHHOHPHQWV7KHVHLQFOXGHFRGHWR
VHDUFKIRUSRWHQWLDOFKHDWLQJORDGEDODQFLQJDFURVVWKHJDPHoV
Web development has moved on considerably since the early
VHUYHUVSOD\HUVNLOOPDWFKPDNLQJDQGWRFKHFNZKHWKHUWKHSOD\HUoV
GD\VRI+70/VFULSWLQJLQDOLPLWHGWH[WHGLWRU7KHPDQ\
FOLHQWVLGHJDPHPDWFKHVWKHVHUYHUoVYHUVLRQV7KHUHoVDOVRD
frameworks and web management services available now
3\WKRQPRGXOHWKDWFDQEHLQFOXGHGLQD0LQHFUDIWVHUYHUHQDEOLQJ
means that building a page has become increasingly complex.
WKHVHUYHUDGPLQWRDGGEORFNVVHQGPHVVDJHVDQGDXWRPDWHDORW
RIWKHEDFNJURXQGFRPSOH[LWLHVRIWKHJDPH
With Python, the web developer has the ability to create
dynamic and highly secure web apps, enabling interaction with
other web services and apps such as Instagram and Pinterest.
Python also allows the collection of data from other websites
and even apps built within other websites.
PYTHON EVERYWHERE
As you can see, Python is quite a versatile
programming language. By learning Python,
you are creating a well-rounded skillset that’s
able to take you into the next generation of
computing, either professionally or simply as
a hobbyist.

Whatever route you decide to take on your


coding journey, you will do well to have
Python in your corner.

ZZZSFOSXEOLFDWLRQVFRP | 13
Getting Started
Pytho
n cre
Ross ator G
um n uido
amed V
There’s a readi
ng sc P ython an
Pyth ripts afte
lot to like about on’s F from Mon r
lying t
Python, but don’t just Circu y
s.
take our word for it. Here are
VRPHDPD]LQJIDFWVDQGƬJXUHV
surrounding one of the most popular
programming languages of recent years.

Alexa, Amazon’s Virtual Data analysis and


Personal Assistant, uses Machine Learning are the
Python to help with two most used Python
speech recognition. examples.

in PYTHON AND
LINUX SKILLS
N UMBERS

As of the end of 2018,


ARE THE THIRD Disney Pixar uses Python
Python was the most MOST POPULAR in its Renderman software
discussed language on I.T. SKILLS IN to operate between other
the Internet. graphics packages.
THE UK.

29(52) 2)$// IT’S ESTIMATED


RECOMMENDED FACEBOOK POSTS 7+$729(52)
CONTENT FROM NETFLIX ARE FILTERED NASA’S WORKFLOW
IS GENERATED FROM 7+528*+3<7+21Ǖ AUTOMATION
0$&+,1(/($51,1*ǟ CODED MACHINE 6<67(0621Ǖ%2$5'
CODED BY PYTHON. LEARNING. THE I.S.S. USE PYTHON.

14 14
| ZZZSFOSXEOLFDWLRQVFRP
Python in Numbers

16,000 3<7+216.,//Ǖ%$6('
POSITIONS ARE THE

th
0267628*+7Ǖ$)7(5
There are over 16,000 Python jobs
posted every six months in the UK. JOBS IN THE UK.

Python Data Science is Google is the top Data Science, Blockchain New York and San
thought to become the company for hiring Python and Machine Learning Francisco are the top
most sought-after job in developers, closely are the fastest growing Python developer cities
the coming years. followed by Microsoft. Python coding skills. in the world.

Python developers enjoy an average salary of

£60,000

2)$//%(*,11(5 2)$//3<7+21 2)$// 2):,1'2:6


CODERS START WITH DEVELOPERS USE PROGRAMMERS USE 10 DEVELOPERS
AND STILL USE, 3<7+21:+(5($6 3<7+2121$'$<Ǖ72Ǖ 86(3<7+21
PYTHON AS THEIR 67,//86(7+( '$<%$6,686( AS THEIR MAIN
PRIMARY OR OUTDATED PYTHON 2 IT AS A SECONDARY PROGRAMMING
SECONDARY LANGUAGE. VERSION. LANGUAGE. LANGUAGE.

ZZZSFOSXEOLFDWLRQVFRP | 15
Getting Started

Why Python?
7KHUHDUHPDQ\GLƪHUHQWSURJUDPPLQJODQJXDJHVDYDLODEOHIRUWKHPRGHUQFRPSXWHU
and some still available for older 8 and 16-bit computers too. Some of these languages
DUHGHVLJQHGIRUVFLHQWLƬFZRUNRWKHUVIRUPRELOHSODWIRUPVDQGVXFK6RZK\FKRRVH
Python out of all the rest?

PYTHON POWER
Ever since the earliest home computers were available, enthusiasts, users and professionals have toiled away until the wee
hours, slaving over an overheating heap of circuitry to create something akin to magic.

7KHVHSLRQHHUVRISURJUDPPLQJFDUYHGWKHLUZD\LQWRDQHZ 5HJDUGOHVVRIZKHWKHU\RXXVHDQ$QGURLGGHYLFHL26GHYLFH3&
frontier, forging small routines that enabled the letter ‘A’ to scroll 0DF/LQX[6PDUW79JDPHVFRQVROH03SOD\HU*36GHYLFHEXLOWLQ
DFURVVWKHVFUHHQ,WPD\QRWVRXQGWHUULEO\H[FLWLQJWRDJHQHUDWLRQ WRDFDUVHWWRSER[RUDWKRXVDQGRWKHUFRQQHFWHGDQGnVPDUWo
WKDWoVXVHGWRXOWUDKLJKGHƬQLWLRQJUDSKLFVDQGRSHQZRUOGPXOWL DSSOLDQFHV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HYHO
/DQJXDJHZKLFKFDQGHDOGLUHFWO\ZLWKPHPRU\DGGUHVVHVFDOO
VWDFNVDQGUHJLVWHUVLWVEHQHƬWLVWKDWLWoVXQLYHUVDOO\DFFHVVLEOH
DQGHDV\WROHDUQ

BASIC was once the starter language that early


8-bit home computer users learned.

Java is a powerful
language that’s used in
web pages, set-top boxes,
TVs and even cars.

Python is a more modern take on BASIC, it’s easy to learn


and makes for an ideal beginner’s programming language.

ZZZSFOSXEOLFDWLRQVFRP 17| 17
Getting Started

Python on the Pi
If you’re considering on which platform to install and use Python, then give some
WKRXJKWWRRQHRIWKHEHVWFRGLQJEDVHVDYDLODEOHWKH5DVSEHUU\3L7KH3LKDVPDQ\
DGYDQWDJHVIRUWKHFRGHULWoVFKHDSHDV\WRXVHDQGH[WUDRUGLQDULO\ƮH[LEOH

THE POWER OF PI
While having a far more powerful coding platform on which to write and test your code is ideal, it’s not often feasible. Most of
XVDUHXQDEOHWRMXPSLQWRDVHYHUDOKXQGUHGSRXQGLQYHVWPHQWZKHQZHoUHVWDUWLQJRƪDQGWKLVLVZKHUHWKH5DVSEHUU\3LFDQ
help out.

While having a far more powerful coding platform on which to kits available will provide the Pi with a pre-loaded SD card (with the
write and test your code is ideal, it’s not often feasible. Most of us latest Raspbian OS), a case, power socket and cables, this is a good
are unable to jump into a several hundred-pound investment when LGHDDV\RXFRXOGZLWKYHU\OLWWOHHƪRUWOHDYHWKH3LSOXJJHGLQWRWKH
ZHoUHVWDUWLQJRƪDQGWKLVLVZKHUHWKH5DVSEHUU\3LFDQKHOSRXW wall under a desk, while still being able to connect to it and code.

7KH5DVSEHUU\3LLVDIDQWDVWLFSLHFHRIPRGHUQKDUGZDUHWKDW 7KHPDLQDGYDQWDJHLVRIFRXUVHWKHH[WUDFRQWHQWWKDWWKH
has created, or rather re-created, the fascination we once all had 5DVSEHUU\3L)RXQGDWLRQKDVLQFOXGHGRXWRIWKHER[7KHUHDVRQ
about computers, how they work, how to code and foundation for this is that the Raspberry Pi’s goal is to help educate the
OHYHOHOHFWURQLFV7KDQNVWRLWVXQLTXHPL[RIKDUGZDUHDQGFXVWRP user, whether that’s coding, electronics, or some other aspect of
software, it has proved itself to be an amazing platform on which to FRPSXWLQJ7RDFKLHYHWKDWJRDOWKH3L)RXQGDWLRQLQFOXGHVGLƪHUHQW
OHDUQKRZWRFRGHVSHFLƬFDOO\XVLQJ3\WKRQ IDEs for the user to compile Python code on; as well as both Python
2 and Python 3, there’s even a Python library that allows you to
While you’re able, with ease, to use the Raspberry Pi to learn to communicate with Minecraft.
code with other programming languages, it’s Python that has been
ƬUPO\SXVKHGWRWKHIRUHIURQW7KH5DVSEHUU\3LXVHV5DVSELDQDV 7KHUHDUHRWKHUDGYDQWDJHVVXFKDVEHLQJDEOHWRFRPELQH3\WKRQ
its recommended, default operating system. Raspbian is a Linux code with Scratch (an Object-Oriented programming language
OS, or to be more accurate, it’s a Debian-based distribution of GHYHORSHGE\0,7IRUFKLOGUHQWRXQGHUVWDQGKRZFRGLQJZRUNV DQG
/LQX[7KLVPHDQVWKDWWKHUHoVDOUHDG\DEXLOWLQHOHPHQWRI3\WKRQ being able to code the GPIO connection on the Pi to further control
programming, as opposed to a fresh installation of Windows 10, any attached robotics or electronics projects. Raspbian also includes
ZKLFKKDVQR3\WKRQVSHFLƬFEDVH+RZHYHUWKH5DVSEHUU\3L D6HQVH+$7(PXODWRU D+$7LVDKDUGZDUHDWWDFKHGSLHFHRI
Foundation has gone the extra mile to include a vast range of FLUFXLWU\WKDWRƪHUVGLƪHUHQWHOHFWURQLFVURERWLFVDQGPRWRULVDWLRQ
Python modules, extensions and even examples, out of the box. projects to the Pi), which can be accessed via Python code.
So, essentially, all you need to do is buy a Raspberry Pi, follow the
instructions on how to set one up (by using one of our excellent Consequently, the Raspberry Pi is an excellent coding base, as well
Raspberry Pi guides found at www.bdmpublications.com) and you as a superb project foundation. It is for these, and many other,
can start coding with Python as soon as the desktop has loaded. reasons we’ve used the Raspberry Pi as our main Python codebase
throughout this title. While the code is written and performed on a
6LJQLƬFDQWO\WKHUHoVDORWPRUHWRWKH5DVSEHUU\3LZKLFKPDNHV Pi, you’re also able to use it in Windows, other versions of Linux and
it an excellent choice for someone who is starting to learn how to PDF26,IWKHFRGHUHTXLUHVDVSHFLƬFRSHUDWLQJV\VWHPWKHQGRQoW
FRGHLQ3\WKRQ7KH3LLVUHPDUNDEO\HDV\WRVHWXSDVDKHDGOHVV worry; we will let you know in the text.
QRGH7KLVPHDQVWKDWZLWKDIHZWZHDNVKHUHDQGWKHUH\RXoUHDEOH
to remotely connect to the Raspberry Pi from any other computer,
Everything you need to learn to code with Python is
or device, on your home network. For example, once you’ve set up
included with the OS!
the remote connectivity options, you can simply plug the Pi into the
power socket anywhere in your house within range of your wireless
router. As long as the Pi is connected, you will be able to remotely
access the desktop from Windows or macOS as easily as if you were
sitting in front of the Pi with a keyboard and mouse.

Using this method saves a lot of money, as you don’t need another
keyboard, mouse and monitor, plus, you won’t need to allocate
VXƯFLHQWVSDFHWRDFFRPPRGDWHWKRVHH[WUDVHLWKHU,I\RXoUHSXVKHG
for space and money, then for around £60, buying one of the many

18 18
| ZZZSFOSXEOLFDWLRQVFRP
Python on the Pi

There’s no such
thing as too
much Pi!

3,Ǖ(9(5
Introduced on 24th June 2019, the Raspberry Pi 4 Model B is
DVLJQLƬFDQWOHDSLQWHUPVRI3LSHUIRUPDQFHDQGKDUGZDUH
VSHFLƬFDWLRQV,WZDVDOVRRQHRIWKHTXLFNHVWPRGHOVDVLGHIURPWKH RI86%SRUWV%OXHWRRWKDQGD*38WKDWoVFDSDEOHRIKDQGLQJ
RULJLQDO3LWRVHOORXW .UHVROXWLRQVDQG2SHQ*/(6JUDSKLFV

:LWKDQHZ*+]ELWTXDGFRUH$50&RUWH[$SURFHVVRUDQG ,QVKRUWWKH3LLVWKHPRVWSRZHUIXORIWKHFXUUHQW5DVSEHUU\3L
DFKRLFHRI*%*%RU*%PHPRU\YHUVLRQVWKH3LLVRQHVWHS PRGHOV+RZHYHUWKHGLƪHUHQWPHPRU\YHUVLRQVKDYHDQLQFUHDVHG
FORVHUWREHFRPLQJDWUXHGHVNWRSFRPSXWHU,QDGGLWLRQWKH3LZDV FRVW7KH*%YHUVLRQFRVWV~*%LV~DQGWKH*%YHUVLRQZLOO
ODXQFKHGZLWKWKHVWDUWOLQJGHFLVLRQWRLQFOXGHGXDOPRQLWRUVXSSRUW VHW\RXEDFN~5HPHPEHUWRDOVRIDFWRULQRQHRUWZRPLFUR+'0,
LQWKHIRUPRIDSDLURIWZRPLFUR+'0,SRUWV<RXoOODOVRƬQGDSDLU FDEOHVZLWK\RXURUGHU

RASPBIAN BUSTER
In addition to releasing the Pi 4, the Raspberry Pi team also compiled
a new version of the Raspbian operating system, codenamed Buster.

In conjunction with the new hardware the Pi 4 boasts, Buster does


RƪHUDIHZXSGDWHV$OWKRXJKRQWKHZKROHLWoVYHU\VLPLODULQ
appearance and operation to the previous version of Raspbian. The
XSGDWHVDUHPDLQO\LQOLQHZLWKWKH.oVGLVSOD\DQGSOD\EDFNJLYLQJWKH
Pi 4 a new set of graphical drivers and performance enhancements.

,QVKRUWZKDW\RXVHHLQWKLVERRNZLOOZRUNZLWKWKH5DVSEHUU\3L
4 and Raspbian Buster!

Once set up, you can remotely connect to the Pi’s desktop You can even test connected hardware with Python
from any device/PC. remotely, via Windows.

ZZZSFOSXEOLFDWLRQVFRP 19| 19
Getting Started

8VLQJ9LUWXDO0DFKLQHV
A Virtual Machine allows you to run an entire operating system from within an app
RQ\RXUGHVNWRS7KLVZD\\RXoUHDEOHWRKRVWPXOWLSOHV\VWHPVLQDVHFXUHVDIHDQG
isolated environment. In short, it’s an ideal way to code.

Sounds good, but what exactly is a Virtual Machine (VM) and


how does it work?
7KHRƯFLDOGHƬQLWLRQRIDYLUWXDOPDFKLQHLVnDQHƯFLHQWLVRODWHG
GXSOLFDWHRIDUHDOFRPSXWHUPDFKLQHo7KLVEDVLFDOO\PHDQVWKDWD
YLUWXDOPDFKLQHLVDQHPXODWHGFRPSXWHUV\VWHPWKDWFDQRSHUDWHLQ
H[DFWO\WKHVDPHZD\DVDSK\VLFDOPDFKLQHEXWZLWKLQWKHFRQƬQHV
RIDGHGLFDWHGYLUWXDOPDFKLQHRSHUDWRURU+\SHUYLVRU

7KH+\SHUYLVRULWVHOILVDQDSSWKDWZLOODOORZ\RXWRLQVWDOOD
VHSDUDWHRSHUDWLQJV\VWHPFUHDWLQJDYLUWXDOFRPSXWHUV\VWHP
ZLWKLQLWVHOIFRPSOHWHZLWKDFFHVVWRWKH,QWHUQHW\RXUKRPH
QHWZRUNDQGVRRQ

7KH+\SHUYLVRUZLOOWDNHUHVRXUFHVIURPWKHKRVWV\VWHP\RXU
SK\VLFDOFRPSXWHUWRFUHDWHWKHYLUWXDOFRPSXWHU7KLVPHDQVWKDW
SDUWRI\RXUSK\VLFDOFRPSXWHUoVPHPRU\&38KDUGGULYHVSDFH
DQGRWKHUVKDUHGUHVRXUFHVZLOOEHVHWDVLGHIRUXVHLQWKHYLUWXDO You’re able to install Linux, and code inside a virtual
PDFKLQHDQGWKHUHIRUHZRQoWEHDYDLODEOHWRWKHSK\VLFDOFRPSXWHU machine on a Windows 10 host.
XQWLOWKHK\SHUYLVRUKDVEHHQFORVHGGRZQ

Black Dog 7KLVUHVRXUFHRYHUKHDG


VIRTUAL OS
NEW Linux Mint 19.1 ¦ Scripting ¦ Python & C++
i-Tech Series
FDQEHFULSSOLQJIRUWKH )URPZLWKLQDK\SHUYLVRU\RXoUHDEOHWRUXQDQXPEHURIGLƪHUHQW

Coding for SK\VLFDOPDFKLQHLI\RX


GRQoWDOUHDG\KDYHHQRXJK
RSHUDWLQJV\VWHPV7KHW\SHRI26GHSHQGVJUHDWO\RQWKH
K\SHUYLVRU\RXoUHUXQQLQJDVVRPHDUHEHWWHUDWHPXODWLQJD

Linux
Master Linux and expand your programming skills

F
PHPRU\RUKDUGGULYH
VSDFHDYDLODEOHRU\RXU
FRPSXWHUKDVDSDUWLFXODUO\
VORZSURFHVVRU:KLOHLWoV
SDUWLFXODUV\VWHPRYHURWKHUV)RUH[DPSOH9LUWXDO%R[DIUHHDQG
HDV\WRXVHK\SHUYLVRUIURP2UDFOHLVJUHDWDWUXQQLQJ:LQGRZV
DQG/LQX[YLUWXDOPDFKLQHVEXWLVQoWVRJRRGDW$QGURLGRUPDF26
4(08LVJRRGIRUHPXODWLQJ$50SURFHVVRUVWKHUHIRUHLGHDOIRU
FULLY REE
UPDATED Code HQWLUHO\SRVVLEOHWRUXQ $QGURLGDQGVXFKEXWLWFDQEHGLƯFXOWWRPDVWHU
ED ITION D ow n lo
With th ad
is issue
YLUWXDOPDFKLQHVRQDVOLWWOH
DV*%RIPHPRU\LWoVQRW 7KHUHDUHSOHQW\RIK\SHUYLVRUVDYDLODEOHWRWU\IRUIUHHZLWKDQ
DGYLVDEOH,GHDOO\\RXZLOO HTXDODPRXQWFRPPHUFLDOO\DYDLODEOHWKDWDUHVLJQLƬFDQWO\PRUH
need a minimum of 8GB
£9.99
Volume 38
US$19.99
SRZHUIXODQGRƪHUEHWWHUIHDWXUHV+RZHYHUIRUPRVWXVHUVERWK
Can$24.50

RIPHPRU\ \RXFDQJHW
Aus$20.25
NZ$19.99
100% INDEPENDENT EHJLQQHUDQGSURIHVVLRQDO9LUWXDO%R[GRHVDJRRGHQRXJKMRE
away with 4GB, but again,
\RXUSK\VLFDOFRPSXWHU :LWKLQDK\SHUYLVRU\RXoUHDEOHWRVHWXSDQGLQVWDOODQ\RIWKH
.. .
ZLOOEHJLQWRVXƪHUZLWK QHZHUGLVWULEXWLRQVRI/LQX[RULI\RXIHHOWKHQHHG\RXoUHDOVRDEOH
de
Packed with Learn Python 3 Start to learn Discover the world
the loss of memory to the
si
In top tips and
tutorials
and apply it to real
world programs
the basics
of C++
of free software
with Linux
WRLQVWDOOVRPHRIWKHPRUHDQWLTXDWHGYHUVLRQV<RXFDQLQVWDOOHDUO\
YLUWXDOPDFKLQH DWOHDVW YHUVLRQV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IXVLQJPXOWLSOH WKDWFRXOGSRWHQWLDOO\FDXVHVRPHLQVWDELOLW\WRWKHFRUH26
RSHUDWLQJV\VWHPVRQDVLQJOHFRPSXWHU GXULQJLWVGHYHORSPHQWSKDVHWKHQH[HFXWLQJDQGWHVWLQJWKDW
FRGHRQDYLUWXDOPDFKLQHPDNHVPRUHVHQVHWKDQWHVWLQJLWRQ\RXU
PDLQFRPSXWHUZKHUHKDYLQJWRUHSHDWHGO\UHERRWRUUHVHW
Even old operating systems can be run inside a
something due to
virtual machine.
the code’s
instabilities, can
become
LQHƯFLHQWDQG
MXVWSODLQ
DQQR\LQJ

7KHYLUWXDO
machine
HQYLURQPHQWFDQ
EHYLHZHGDVD Coding in Python on the Raspberry
sandbox, where Pi Desktop OS inside a VM on
you’re able to test Windows 10!
unsecure, or
unstable code without it causing harm, or doing damage, to your
PDLQZRUNLQJFRPSXWHU9LUXVHVDQGPDOZDUHFDQEHLVRODWHG
ZLWKLQWKH90ZLWKRXWLQIHFWLQJWKHPDLQFRPSXWHU\RXoUHDEOH
WRVHWXSDQRQ\PLW\,QWHUQHWXVHZLWKLQWKH90DQG\RXoUHDEOH
WRLQVWDOOWKLUGSDUW\VRIWZDUHZLWKRXWLWVORZLQJGRZQ\RXU
Virtual machines can be as simple, or as complex as your
PDLQFRPSXWHU
needs require.

GOING VIRTUAL
:KLOH\RXoUHDWWKHHDUO\VWDJHVRIFRGLQJXVLQJDYLUWXDOPDFKLQH
PD\VHHPDOLWWOHH[FHVVLYH+RZHYHULWoVZRUWKORRNLQJLQWREHFDXVH
FRGLQJLQ/LQX[FDQRIWHQEHHDVLHUWKDQFRGLQJLQ:LQGRZVDVVRPH
YHUVLRQVRI/LQX[KDYH,'(VSUHLQVWDOOHG(LWKHUZD\YLUWXDOLVDWLRQRI
DQRSHUDWLQJV\VWHPLVKRZPDQ\RIWKHSURIHVVLRQDODQGVXFFHVVIXO
FRGHUVDQGGHYHORSHUVZRUNVRJHWWLQJXVHGWRLWHDUO\RQLQ\RXU
VNLOOVHWLVDGYDQWDJHRXV

7RVWDUWORRNDWLQVWDOOLQJ9LUWXDO%R[7KHQFRQVLGHUWDNLQJDORRN
DWRXU/LQX[WLWOHVhttps://bdmpublications.com/?s=linux&post_
type=productWROHDUQKRZWRLQVWDOO/LQX[LQDYLUWXDOHQYLURQPHQW
DQGKRZEHVWWRXWLOLVHWKHRSHUDWLQJV\VWHP

ZZZSFOSXEOLFDWLRQVFRP 21| 21
Getting Started

Creating a
Coding Platform
7KHWHUPn&RGLQJ3ODWIRUPoFDQGHQRWHDW\SHRIKDUGZDUHRQZKLFK\RXFDQFRGH
or a particular operating system, or even a custom environment that’s pre-built and
designed to allow the easy creation of games. In truth it’s quite a loose term, as a
Coding Platform can be a mixture of all these ingredients, it’s simply down to what
programming language you intend to code in and what your end goals are.

Coding can be one of those experiences that sounds fantastic, but


to get going with it, is often confusing. After all, there’s a plethora
of languages to choose from, numerous apps that will enable you
WRFRGHLQDVSHFLƬFRUUDQJHRIODQJXDJHVDQGDQHTXDOO\KXJH
DPRXQWRIWKLUGSDUW\VRIWZDUHWRFRQVLGHU7KHQ\RXDFFHVVWKH
Internet and discover that there are countless coding tutorials
available, for the language in which you’ve decided you want to
program, alongside even more examples of code. It’s all a little too
much at times.

7KHWULFNLVWRVORZGRZQDQGWREHJLQZLWKQRWORRNWRRGHHSO\
into coding. Like all good projects, you need a solid foundation
on which to build your skill and to have all the necessary tools
DYDLODEOHWRKDQGWRHQDEOH\RXWRFRPSOHWHWKHEDVLFVWHSV7KLV
is where creating a coding platform comes in, as it will be your
OHDUQLQJIRXQGDWLRQZKLOH\RXEHJLQWRWDNH\RXUƬUVWWHQWDWLYH
steps into the wider world of coding.

HARDWARE SOFTWARE
7KDQNIXOO\FRGLQJDWWKH ,QWHUPVRIVRIWZDUH
IRXQGDWLRQOHYHOGRHVQoW PRVWRIWKHGHYHORSPHQW
UHTXLUHVSHFLDOLVWHTXLSPHQW HQYLURQPHQWVWKHWRROV
RUDW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QHHGWRVWDUWVORZPDVWHUWKH
EDVLFVOHDUQKRZWRJHWDUHVXOWDQGKRZWRJHWZKDW\RXZDQW
IURPWKHFRGH
7KLVVHFWLRQFRYHUVQXPEHUVDQGH[SUHVVLRQVXVHULQSXW
FRQGLWLRQVDQGORRSVDQGWKHW\SHVRIHUURUV\RXZLOO
XQGRXEWHGO\FRPHDFURVVLQ\RXUWLPHZLWK3\WKRQWKHFRUH
IRXQGDWLRQVRIgood coding and Python code.

ZZZSFOSXEOLFDWLRQVFRP 25| 25
Hello, World

Equipment You
Will Need
<RXFDQOHDUQ3\WKRQZLWKYHU\OLWWOHKDUGZDUHRULQLWLDOƬQDQFLDOLQYHVWPHQW<RX
don’t need an incredibly powerful computer and any software that’s required is
IUHHO\{DYDLODEOH

:+$7:(o5(86,1*
7KDQNIXOO\3\WKRQLVDPXOWLSODWIRUPSURJUDPPLQJODQJXDJHDYDLODEOHIRU:LQGRZVPDF26/LQX[5DVSEHUU\3LDQGPRUH,I
\RXKDYHRQHRIWKRVHV\VWHPVWKHQ\RXFDQHDVLO\VWDUWXVLQJ3\WKRQ

&20387(5
Obviously you’re going to need a computer in order to learn how to program in
Python and to test your code. You can use Windows (from XP onward) on either a 32
or 64-bit processor, an Apple Mac or Linux installed PC.

$1,'(
An IDE (Integrated Developer Environment) is used to enter and execute Python
code. It enables you to inspect your program code and the values within the code, as
ZHOODVRƪHULQJDGYDQFHGIHDWXUHV7KHUHDUHPDQ\GLƪHUHQW,'(VDYDLODEOHVRƬQG
the one that works for you and gives the best results.

3<7+2162)7:$5(
macOS and Linux already come with Python preinstalled as part of the operating
system, as does the Raspberry Pi. However, you need to ensure that you’re running
the latest version of Python. Windows users need to download and install Python,
which we’ll cover shortly.

7(;7(',725
Whilst a text editor is an ideal environment to enter code into, it’s not an absolute
necessity. You can enter and execute code directly from the IDLE but a text editor,
VXFKDV6XEOLPH7H[WRU1RWHSDGRƪHUVPRUHDGYDQFHGIHDWXUHVDQGFRORXUFRGLQJ
when entering code.

,17(51(7$&&(66
Python is an ever evolving environment and as such new versions often introduce
new concepts or change existing commands and code structure to make it a more
HƯFLHQWODQJXDJH+DYLQJDFFHVVWRWKH,QWHUQHWZLOONHHS\RXXSWRGDWHKHOS\RX
out when you get stuck and give access to Python’s immense number of modules.

7,0($1'3$7,(1&(
Despite what other books may lead you to believe, you won’t become a programmer
in 24-hours. Learning to code in Python takes time, and patience. You may become
VWXFNDWWLPHVDQGRWKHUWLPHVWKHFRGHZLOOƮRZOLNHZDWHU8QGHUVWDQG\RXoUHOHDUQLQJ
something entirely new, and you will get there.

26 26
| ZZZSFOSXEOLFDWLRQVFRP
Equipment You Will Need

7+(5$63%(55<3,
:K\XVHD5DVSEHUU\3L"7KH5DVSEHUU\3LLVDWLQ\FRPSXWHUWKDWoVYHU\FKHDSWRSXUFKDVHEXWRƪHUVWKHXVHUDIDQWDVWLFOHDUQLQJ
SODWIRUP,WVPDLQRSHUDWLQJV\VWHP5DVSELDQFRPHVSUHLQVWDOOHGZLWKWKHODWHVW3\WKRQDORQJZLWKPDQ\PRGXOHVDQGH[WUDV

5$63%(55<3,
The Raspberry Pi 4 Model B is the latest version,
LQFRUSRUDWLQJDPRUHSRZHUIXO&38DFKRLFHRI*%
*%RU*%PHPRU\YHUVLRQVDQG:L)LDQG%OXHWRRWK
support. You can pick up a Pi from around £33, increasing
XSWR~IRUWKH*%PHPRU\YHUVLRQRUDVDSDUWRINLW
for £50+, depending on the kit you’re interested in.

)8=(352-(&7
7KH)8=(LVDOHDUQLQJHQYLURQPHQWEXLOWRQWKHODWHVWPRGHO
of the Raspberry Pi. You can purchase the workstations that
come with an electronics kit and even a robot arm for you
WREXLOGDQGSURJUDP<RXFDQƬQGPRUHLQIRUPDWLRQRQWKH
)8=(DWZZZIX]HFRXN

5$63%,$1
The Raspberry Pi’s main operating system is a Debian-based
Linux distribution that comes with everything you need in
a simple to use package. It’s streamlined for the Pi and is an
ideal platform for hardware and software projects, Python
programming and even as a desktop computer.
Hello, World

*HWWLQJWR
Know Python
Python is the greatest computer programming language ever created. It enables
you to fully harness the power of a computer, in a language that’s clean and easy
WR{XQGHUVWDQG

:+$7,6352*5$00,1*"
,WKHOSVWRXQGHUVWDQGZKDWDSURJUDPPLQJODQJXDJHLVEHIRUH\RXWU\WROHDUQRQHDQG3\WKRQLVQRGLƪHUHQW/HWoVWDNHD
ORRNDWKRZ3\WKRQFDPHDERXWDQGKRZLWUHODWHVWRRWKHUODQJXDJHV

3<7+21 352*5$00,1*5(&,3(6
Programs are like recipes for computers. A
A programming language recipe to bake a cake could go like this:
is a list of instructions that
a computer follows. These 3XWJUDPVRIVHOIUDLVLQJƮRXULQDERZO
instructions can be as simple $GGJUDPVRIEXWWHUWRWKHERZO
as displaying your name $GGPLOOLOLWUHVRIPLON
RUSOD\LQJDPXVLFƬOHRU Bake for half an hour.
as complex as building a
whole virtual world. Python
is a programming language
FRQFHLYHGLQWKHODWHV
&2'(
E\*XLGRYDQ5RVVXP Just like a recipe, a program consists of instructions that you follow
at Centrum Wiskunde & in order. A program that describes a cake might run like this:
Informatica (CWI) in the
bowl = []
Netherlands as a successor to
flour = 100
the ABC language.
butter = 50
milk = 100
*XLGRYDQ5RVVXPWKH
bowl.append([flour,butter,milk])
IDWKHURI3\WKRQ
cake.cook(bowl)

352*5$0&200$1'6
You might not understand some of the Python commands, like bowl.append and cake.cook(bowl).
7KHƬUVWLVDOLVWWKHVHFRQGDQREMHFWZHoOOORRNDWERWKLQWKLVERRN7KHPDLQWKLQJWRNQRZLV
that it’s easy to read commands in Python. Once you learn what the commands do, it’s easy to
ƬJXUHRXWKRZDSURJUDPZRUNV

28 28
| ZZZSFOSXEOLFDWLRQVFRP
Getting to Know Python

+,*+Ǖ/(9(//$1*8$*(6 =(12)3<7+21
Computer languages that are easy to read are known as “high-level”. Python lets you access all the power of a computer in a language
7KLVLVEHFDXVHWKH\Ʈ\KLJKDERYHWKHKDUGZDUH DOVRUHIHUUHGWRDV that humans can understand. Behind all this is an ethos called “The
pWKHPHWDOq /DQJXDJHVWKDWpƮ\FORVHWRWKHPHWDOqOLNH$VVHPEO\ =HQRI3\WKRQq7KLVLVDFROOHFWLRQRIVRIWZDUHSULQFLSOHVWKDW
are known as “low-level”. Low-level languages commands read a bit LQƮXHQFHVWKHGHVLJQRIWKHODQJXDJH3ULQFLSOHVLQFOXGHp%HDXWLIXO
like this: msg db ,0xa len equ $ - msg. is better than ugly” and “Simple is better than complex.” Type
import this into Python and it will display all the principles.

3<7+21963<7+21
,QDW\SLFDOFRPSXWLQJVFHQDULR3\WKRQLVFRPSOLFDWHGVRPHZKDWE\WKHH[LVWHQFHRIWZRDFWLYHYHUVLRQVRIWKHODQJXDJH
Python 2 and Python 3.

:25/'2)3<7+21 Python 3.7 is the newest release 3<7+21; In 2008 Python 3 arrived with several new
of the programming language. and enhanced features. These features
However, if you dig a little deeper into the Python site, and investigate SURYLGHDPRUHVWDEOHHƪHFWLYHDQGHƯFLHQWSURJUDPPLQJ
Python code online, you will undoubtedly come across Python 2. environment but sadly, most (if not all) of these new features are
Although you can run Python 3 and Python 2 alongside each other, it’s not compatible with Python 2 scripts, modules and tutorials. Whilst
not recommended. Always opt for the latest stable release as posted QRWSRSXODUDWƬUVW3\WKRQKDVVLQFHEHFRPHWKHFXWWLQJHGJHRI
by the Python website. Python programming.

3<7+21; So why two? Well, Python 2 was originally ;:,16 Python 3’s growing popularity has meant that
launched in 2000 and has since then it’s now prudent to start learning to develop
adopted quite a large collection of modules, scripts, users, tutorials with the new features and begin to phase out the previous version.
DQGVRRQ2YHUWKH\HDUV3\WKRQKDVIDVWEHFRPHRQHRIWKHƬUVW Many development companies, such as SpaceX and NASA use
go to programming languages for beginners and experts to code Python 3 for snippets of important code.
in, which makes it an extremely valuable resource.

ZZZSFOSXEOLFDWLRQVFRP 29| 29
Hello, World

+RZWR6HW8S
Python in Windows
Windows users can easily install the latest version of Python via the main Python
Downloads page. Whilst most seasoned Python developers may shun Windows as the
platform of choice for building their code, it’s still an ideal starting point for beginners.

,167$//,1*3<7+21;
0LFURVRIW:LQGRZVGRHVQoWFRPHZLWK3\WKRQSUHLQVWDOOHGDVVWDQGDUGVRLWZLOOEHQHFHVVDU\WRLQVWDOOLW\RXUVHOIPDQXDOO\
7KDQNIXOO\LWoVDQHDV\SURFHVVWRIROORZ

67(3 Start by opening your web browser to www.python. 67(3 Choosing the Customise option allows you to
org/downloads/. Look for the button detailing the specify certain parameters, and whilst you may
Download link for Python 3.x. Python is regularly updated, changing stay with the defaults, it’s a good habit to adopt as, sometimes (not
WKHODVWGLJLWIRUHDFKEXJƬ[DQGXSGDWH7KHUHIRUHGRQoWZRUU\LI with Python, thankfully), installers can include unwanted additional
\RXVHH3\WKRQRUPRUHDVORQJDVLWoV3\WKRQWKHFRGHLQWKLV IHDWXUHV2QWKHƬUVWVFUHHQDYDLODEOHHQVXUHDOOER[HVDUHWLFNHG
ERRNZLOOZRUNƬQH and click the Next button.

67(3 Click the Download button for version 3.x and 67(3 The next page of options include some interesting
VDYHWKHƬOHWR\RXU'RZQORDGVIROGHU:KHQWKH DGGLWLRQVWR3\WKRQ(QVXUHWKH$VVRFLDWHƬOHZLWK
ƬOHLVGRZQORDGHGGRXEOHFOLFNWKHH[HFXWDEOHDQGWKH3\WKRQ Python, Create Shortcuts, Add Python to Environment Variables,
LQVWDOODWLRQZL]DUGZLOOODXQFK)URPKHUH\RXKDYHWZRFKRLFHV 3UHFRPSLOH6WDQGDUG/LEUDU\DQG,QVWDOOIRU$OO8VHUVRSWLRQVDUH
Install Now and Customise Installation. We recommend opting for ticked. These make using Python later much easier. Click Install when
the Customise Installation link. you’re ready to continue.

30 30
| ZZZSFOSXEOLFDWLRQVFRP
How to Set Up Python in Windows

67(3 <RXPD\QHHGWRFRQƬUPWKHLQVWDOODWLRQZLWK 67(3 Clicking on the IDLE (Python 3.x 32-bit) link will launch
WKH:LQGRZVDXWKHQWLFDWLRQQRWLƬFDWLRQ6LPSO\ the Python Shell, where you can begin your Python
click Yes and Python will begin to install. Once the installation is programming journey. Don’t worry if your version is newer, as long
FRPSOHWHWKHƬQDO3\WKRQZL]DUGSDJHZLOODOORZ\RXWRYLHZWKH as it’s Python 3.x our code works inside your Python 3 interface.
latest release notes and follow some online tutorials.

67(3 %HIRUH\RXFORVHWKHLQVWDOOZL]DUGZLQGRZ 67(3 If you now click on the Windows Start button again,
however, it’s best to click on the link next to the and this time type: CMD, you’ll be presented with
shield detailed Disable Path Length Limit. This will allow Python the Command Prompt link. Click it to get to the Windows command
to bypass the Windows 260 character limitation, enabling you to line environment. To enter Python within the command line, you
execute Python programs stored in deep folders arrangements. need to type: python and press Enter.
Click Yes again, to authenticate the process, then you can Close the
installation window.

67(3 :LQGRZVXVHUVFDQQRZƬQGWKHLQVWDOOHG3\WKRQ 67(3 The command line version of Python works in


3.x within the Start button Recently Added section. much the same way as the Shell you opened in
7KHƬUVWOLQN3\WKRQ[ ELW ZLOOODXQFKWKHFRPPDQGOLQH 6WHSQRWHWKHWKUHHOHIWIDFLQJDUURZV !!! :KLOVWLWoVDSHUIHFWO\
version of Python when clicked (more on that in a moment). To open ƬQHHQYLURQPHQWLWoVQRWWRRXVHUIULHQGO\VROHDYHWKHFRPPDQG
the IDLE, type IDLE into Windows start. line for now. Enter: exit() to leave and close the Command
Prompt window.

ZZZSFOSXEOLFDWLRQVFRP | 31
Hello, World

+RZWR6HW8S
Python in Linux
While the Raspberry Pi’s operating system contains the latest, stable version of Python,
other Linux distros don’t come with Python 3 pre-installed. If you’re not going down
the Pi route, then here’s how to check and install Python for Linux.

3<7+213(1*8,1
/LQX[LVVXFKDYHUVDWLOHRSHUDWLQJV\VWHPWKDWLWoVRIWHQGLƯFXOWWRQDLOGRZQMXVWRQHZD\RIGRLQJVRPHWKLQJ'LƪHUHQW
GLVWULEXWLRQVJRDERXWLQVWDOOLQJVRIWZDUHLQGLƪHUHQWZD\VVRIRUWKLVSDUWLFXODUWXWRULDOZHZLOOVWLFNWR/LQX[0LQW

)LUVW\RXQHHGWRDVFHUWDLQZKLFKYHUVLRQRI3\WKRQ Once the update and upgrade completes, enter:


67(3 67(3
is currently installed in your Linux system. To begin python3 --version again to see if Python 3.x is
with, drop into a Terminal session from your distro’s menu, or hit the updated, or even installed. As long as you have Python 3.x, you’re
Ctrl+Alt+T keys. running the most recent major version, the numbers after the 3.
indicate patches plus further updates. Often they’re unnecessary,
but they can contain vital new elements.

Next, enter: python --version into the Terminal


67(3
screen. You should have the output relating to
version 2.x of Python in the display. Most Linux distro come with
both Python 2 and 3 by default, as there’s plenty of code out there
still available for Python 2. Now enter: python3 --version.

However, if you want the latest, cutting edge


67(3
version, you’ll need to build Python from source.
Start by entering these commands into the Terminal:
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev
libncursesw5-dev libssl-dev libsqlite3-dev tk-dev
In our case we have both Python 2 and 3 installed. libgdbm-dev libc6-dev libbz2-dev
67(3
As long as Python 3.x.x is installed, then the code in
our tutorials will work. It’s always worth checking to see if the distro
has been updated with the latest versions, enter: sudo apt-get
update && sudo apt-get upgrade to update the system.

32 32
| ZZZSFOSXEOLFDWLRQVFRP
How to Set Up Python in Linux

Open up your Linux web browser and go to the )RUWKH*8,,'/(\RXoOOQHHGWRHQWHUWKHIROORZLQJ


67(3 67(3
Python download page: https://www.python.org/ command into the Terminal:
downloads. Click on the Downloads, followed by the button under
sudo apt-get install idle3
the Python Source window. This opens a download dialogue box,
choose a location, then start the download process. The IDLE can then be started with the command: idle3. Note, that
,'/(UXQVDGLƪHUHQWYHUVLRQWRWKHRQH\RXLQVWDOOHGIURPVRXUFH

In the Terminal, go to the Downloads folder


67(3
by entering: cd Downloads/7KHQXQ]LSWKH
contents of the downloaded Python source code with: tar -xvf
Python-3.Y.Y.tar.xz (replace the Y’s with the version numbers
\RXoYHGRZQORDGHG 1RZHQWHUWKHQHZO\XQ]LSSHGIROGHUZLWKcd
Python-3.Y.Y/. You’ll also need PIP (Pip Installs Packages), which is
67(3
a tool to help you install more modules and extras.
Enter: sudo apt-get install python3-pip
Once PIP is installed, check for the latest update with:
pip3 install --upgrade pip
When complete, close the Terminal and Python 3.x will be available
via the Programming section in your distro’s menu.

Within the Python folder, enter:


67(3
./configure
sudo make altinstall
This could take a while, depending on the speed of your computer.
2QFHƬQLVKHGHQWHUpython3.7 --version to check the latest
installed version. You now have Python 3.7 installed, alongside older
Python 3.x.x and Python 2.

3<7+2121mac26
Installation of Python on macOS can be done in much the
same way as the Windows installation. Simply go to the Python
webpage, hover your mouse pointer over the Downloads
link and select Mac OS X from the options. You will then be
guided to the Python releases for Mac versions, along with the
QHFHVVDU\LQVWDOOHUVIRUPDF26ELWIRU26;DQGODWHU

ZZZSFOSXEOLFDWLRQVFRP 33| 33
Hello, World

Starting Python for


WKH)LUVW7LPH
7KH5DVSEHUU\3LRƪHUVRQHRIWKHEHVWDOOURXQGVROXWLRQVRQZKLFKWROHDUQDQGFRGH
in particular, Python. Raspbian, the Pi’s recommended OS, come pre-installed with the
latest stable version of Python 3, which makes it a superb coding platform.

67$57,1*3<7+21
(YHU\WKLQJ\RXQHHGWREHJLQSURJUDPPLQJZLWK3\WKRQLVDYDLODEOHIURPWKH5DVSEHUU\3LGHVNWRS+RZHYHULI\RXZDQW
GURSLQWRWKH7HUPLQDODQGXSGDWHWKHV\VWHPZLWKVXGRDSWJHWXSGDWH

67(3 With the Raspbian desktop loaded, click on the 67(3 )RUH[DPSOHLQWKH6KHOOHQWHU2+2
0HQXEXWWRQIROORZHGE\3URJUDPPLQJ!3\WKRQ After pressing Enter, the next line displays the
3 (IDLE). This opens the Python 3 Shell. Windows and Mac users can answer: 4. Basically, Python has taken the ‘code’ and produced the
ƬQGWKH3\WKRQ,'/(6KHOOIURPZLWKLQWKH:LQGRZV6WDUWEXWWRQ relevant output.
PHQXDQGYLD)LQGHU

67(3 The Shell is where you can enter code and see the 67(3 The Python Shell acts very much like a calculator,
responses and output of code you’ve programmed since code is basically a series of mathematical
into Python. This is a kind of sandbox, where you’re able to try out LQWHUDFWLRQVZLWKWKHV\VWHP,QWHJHUVZKLFKDUHWKHLQƬQLWH
some simple code and processes. sequence of whole numbers can easily be added, subtracted,
multiplied and so on.

34 34
| ZZZSFOSXEOLFDWLRQVFRP
Starting Python for the First Time

67(3 While that’s very interesting, it’s not particularly 67(3 7KH3\WKRQ,'/(LVDFRQƬJXUDEOHHQYLURQPHQW,I
exciting. Instead, try this: you don’t like the way the colours are represented,
WKHQ\RXFDQDOZD\VFKDQJHWKHPYLD2SWLRQV!&RQƬJXUH,'/(DQG
print(“Hello everyone!”)
clicking on the Highlighting tab. However, we don’t recommend
Just enter it into the IDLE as you’ve done in the previous steps. that, as you won’t be seeing the same as our screenshots.

67(3 This is a little more like it, since you’ve just produced 67(3 Just like most programs available, regardless of the
\RXUƬUVWELWRIFRGH7KH3ULQWFRPPDQGLVIDLUO\ operating system, there are numerous shortcut
self-explanatory, it prints things. Python 3 requires the brackets as keys available. We don’t have room for them all here but within the
well as quote marks in order to output content to the screen, in this 2SWLRQV!&RQƬJXUH,'/(DQGXQGHUWKH.H\VWDE\RXFDQVHHDOLVW
case the ‘Hello everyone!’ bit. of the current bindings.

67(3 You may have noticed the colour coding within 67(3 The Python IDLE is a power interface and one
WKH3\WKRQ,'/(7KHFRORXUVUHSUHVHQWGLƪHUHQW that’s actually been written in Python using one
elements of Python code. They are: RIWKHDYDLODEOH*8,WRRONLWV,I\RXZDQWWRNQRZWKHPDQ\LQVDQG
outs of the Shell, we recommend you take a few moments to view
Black – Data and Variables %OXHs8VHU)XQFWLRQV
ZZZGRFVS\WKRQRUJOLEUDU\LGOHKWPO, which details many of
*UHHQs6WULQJV Dark Red – Comments
the IDLE’s features.
3XUSOHs)XQFWLRQV Light Red – Error Messages
Orange – Commands

ZZZSFOSXEOLFDWLRQVFRP 35| 35
Hello, World

<RXU)LUVW&RGH
(VVHQWLDOO\\RXoYHDOUHDG\ZULWWHQ\RXUƬUVWSLHFHRIFRGHZLWKWKHnSULQW p+HOOR
everyone!”)’ function from the previous tutorial. However, let’s expand that and look at
entering your code and playing around with some other Python examples.

3/$<,1*:,7+3<7+21
:LWKPRVWODQJXDJHVFRPSXWHURUKXPDQLWoVDOODERXWUHPHPEHULQJDQGDSSO\LQJWKHULJKWZRUGVWRWKHULJKWVLWXDWLRQ
<RXoUHQRWERUQNQRZLQJWKHVHZRUGVVR\RXQHHGWROHDUQWKHP

67(3 If you’ve closed Python 3 IDLE, reopen it in 67(3 You can see that instead of the number 4, the
whichever operating system version you prefer. In output is the 2+2 you asked to be printed to the
the Shell, enter the familiar following: VFUHHQ7KHTXRWDWLRQPDUNVDUHGHƬQLQJZKDWoVEHLQJRXWSXWWHG
to the IDLE Shell; to print the total of 2+2 you need to remove
print(“Hello”)
the quotes:
print(2+2)

67(3 Just as predicted, the word Hello appears in the 67(3 You can continue as such, printing 2+2, 464+2343
Shell as blue text, indicating output from a string. and so on to the Shell. An easier way is to use a
It’s fairly straightforward and doesn’t require too much explanation. YDULDEOHZKLFKLVVRPHWKLQJZHZLOOFRYHULQPRUHGHSWKODWHU)RU
Now try: now, enter:
print(“2+2”) a=2
b=2

36 36
| ZZZSFOSXEOLFDWLRQVFRP
Your First Code

67(3 What you have done here is assign the letters a 67(3 Now let’s add a surname:
and b two values: 2 and 2. These are now variables,
surname=”Hayward”
which can be called upon by Python to output, add, subtract, divide
print(surname)
and so on for as long as their numbers stay the same. Try this:
<RXQRZKDYHWZRYDULDEOHVFRQWDLQLQJDƬUVWQDPHDQGDVXUQDPH
print(a)
and you can print them independently.
print(b)

67(3 The output of the last step displays the current 67(3 If we were to apply the same routine as before,
values of both a and b individually, as you’ve asked using the + symbol, the name wouldn’t appear
them to be printed separately. If you want to add them up, you can correctly in the output in the Shell. Try it:
use the following:
print(name+surname)
print(a+b)
<RXQHHGDVSDFHEHWZHHQWKHWZRGHƬQLQJWKHPDVWZRVHSDUDWH
This code simply takes the values of a and b, adds them together values and not something you mathematically play around with.
and outputs the result.

67(3 <RXFDQSOD\DURXQGZLWKGLƪHUHQWNLQGVRIYDULDEOHV 67(3 In Python 3 you can separate the two variables
DQGWKH3ULQWIXQFWLRQ)RUH[DPSOH\RXFRXOG with a space using a comma:
assign variables for someone’s name:
print(name, surname)
name=”David”
Alternatively, you can add the space yourself:
print(name)
print(name+” “+surname)
The use of the comma is much neater, as you can see.
&RQJUDWXODWLRQV\RXoYHMXVWWDNHQ\RXUƬUVWVWHSVLQWRWKHZLGH
world of Python.

ZZZSFOSXEOLFDWLRQVFRP 37| 37
Hello, World

Saving and Executing


Your Code
:KLOHZRUNLQJLQWKH,'/(6KHOOLVSHUIHFWO\ƬQHIRUVPDOOFRGHVQLSSHWVLWoVQRW
designed for entering longer program listings. In this section you’re going to be
introduced to the IDLE Editor, where you will be working from now on.

(',7,1*&2'(
<RXZLOOHYHQWXDOO\UHDFKDSRLQWZKHUH\RXKDYHWRPRYHRQIURPLQSXWWLQJVLQJOHOLQHVRIFRGHLQWRWKH6KHOO,QVWHDGWKH
,'/((GLWRUZLOODOORZ\RXWRVDYHDQGH[HFXWH\RXU3\WKRQFRGH

67(3 )LUVWRSHQWKH3\WKRQ,'/(6KHOODQGZKHQLWoVXS 67(3 You can see that the same colour coding is in place
FOLFNRQ)LOH!1HZ)LOH7KLVZLOORSHQDQHZZLQGRZ in the IDLE Editor as it is in the Shell, enabling you
ZLWK8QWLWOHGDVLWVQDPH7KLVLVWKH3\WKRQ,'/((GLWRUDQGZLWKLQLW to better understand what’s going on with your code. However, to
you can enter the code needed to create your future programs. H[HFXWHWKHFRGH\RXQHHGWRƬUVWVDYHLW3UHVV)DQG\RXJHWD
Save…Check box open.

67(3 The IDLE Editor is, for all intents and purposes, a 67(3 Click on the OK button in the Save box and select a
simple text editor with Python features, colour destination where you’ll save all your Python code.
coding and so on; much in the same vein as Sublime. You enter The destination can be a dedicated folder called Python or you
code as you would within the Shell, so taking an example from the can just dump it wherever you like. Remember to keep a tidy drive
previous tutorial, enter: though, to help you out in the future.
print(“Hello everyone!”)

38 38
| ZZZSFOSXEOLFDWLRQVFRP
Saving and Executing Your Code

67(3 Enter a name for your code, ‘print hello’ for 67(3 Let’s extend the code and enter a few examples
example, and click on the Save button. Once the from the previous tutorial:
Python code is saved it’s executed and the output will be detailed in
a=2
the IDLE Shell. In this case, the words ‘Hello everyone!’.
b=2
name=”David”
surname=”Hayward”
print(name, surname)
print (a+b)
,I\RXSUHVV)QRZ\RXoOOEHDVNHGWRVDYHWKHƬOHDJDLQDVLWoVEHHQ
PRGLƬHGIURPEHIRUH

67(3 This is how the vast majority of your Python code 67(3 ,I\RXFOLFNWKH2.EXWWRQWKHƬOHZLOOEH
ZLOOEHFRQGXFWHG(QWHULWLQWRWKH(GLWRUKLW) overwritten with the new code entries, and
save the code and look at the output in the Shell. Sometimes things executed, with the output in the Shell. It’s not a problem with just
ZLOOGLƪHUGHSHQGLQJRQZKHWKHU\RXoYHUHTXHVWHGDVHSDUDWH WKHVHIHZOLQHVEXWLI\RXZHUHWRHGLWDODUJHUƬOHRYHUZULWLQJFDQ
window, but essentially that’s the process. It’s the process we will EHFRPHDQLVVXH,QVWHDGXVH)LOH!6DYH$VIURPZLWKLQWKH(GLWRU
use throughout this book, unless otherwise stated. to create a backup.

67(3 ,I\RXRSHQWKHƬOHORFDWLRQRIWKHVDYHG3\WKRQ 67(3 1RZFUHDWHDQHZƬOH&ORVHWKH(GLWRUDQGRSHQ


code, you can see that it ends in a .py extension. DQHZLQVWDQFH )LOH!1HZ)LOHIURPWKH6KHOO 
7KLVLVWKHGHIDXOW3\WKRQƬOHQDPH$Q\FRGH\RXFUHDWHZLOOEH Enter the following and save it as hello.py:
whatever.py and any code downloaded from the many Internet
a=”Python”
Python resource sites will be .py. Just ensure that the code is written
b=”is”
for Python 3.
c=”cool!”
print(a, b, c)
You will use this code in the next tutorial.

39| 39
Hello, World

Executing Code from


the Command Line
Although we’re working from the GUI IDLE throughout this book, it’s worth taking
a look at Python’s command line handling. We already know there’s a command line
version of Python but it’s also used to execute code.

&200$1'7+(&2'(
8VLQJWKHFRGHZHFUHDWHGLQWKHSUHYLRXVWXWRULDOWKHRQHZHQDPHGKHOORS\OHWoVVHHKRZ\RXFDQUXQFRGHWKDWZDVPDGH
LQWKH*8,DWWKHFRPPDQGOLQHOHYHO

67(3 Python, in Linux, comes with two possible ways of 67(3 Now you’re at the command line we can start
executing code via the command line. One of the 3\WKRQ)RU3\WKRQ\RXQHHGWRHQWHUWKH
ways is with Python 2, whilst the other uses the Python 3 libraries command python3 and press Enter. This will put you into the
DQGVRRQ)LUVWWKRXJKGURSLQWRWKHFRPPDQGOLQHRU7HUPLQDORQ command line version of the Shell, with the familiar three right-
your operating system. IDFLQJDUURZVDVWKHFXUVRU !!! 

67(3 Just as before, 67(3 )URPKHUH\RXoUHDEOHWRHQWHUWKHFRGH\RXoYH


we’re using a looked at previously, such as:
Raspberry Pi: Windows users will
a=2
need to click the Start button and
print(a)
search for CMD, then click the
Command Line returned search; You can see that it works exactly the same.
and macOS users can get access
to their command line by clicking
*R!8WLOLWLHV!7HUPLQDO

40 40
| ZZZSFOSXEOLFDWLRQVFRP
Executing Code from the Command Line

67(3 Now enter: exit() to leave the command line Python 67(3 The result of running Python 3 code from the
session and return you back to the command Python 2 command line is quite obvious. Whilst it
prompt. Enter the folder where you saved the code from the GRHVQoWHUURURXWLQDQ\ZD\GXHWRWKHGLƪHUHQFHVEHWZHHQWKH
SUHYLRXVWXWRULDODQGOLVWWKHDYDLODEOHƬOHVZLWKLQKRSHIXOO\\RX way Python 3 handles the Print command over Python 2, the result
VKRXOGVHHWKHKHOORS\ƬOH LVQoWDVZHH[SHFWHG8VLQJ6XEOLPHIRUWKHPRPHQWRSHQWKH
KHOORS\ƬOH

67(3 )URPZLWKLQWKHVDPHIROGHUDVWKHFRGH\RXoUH 67(3 Since Sublime Text isn’t available for the Raspberry
going to run, enter the following into the Pi, you’re going to temporarily leave the Pi for the
command line: moment and use Sublime as an example that you don’t necessarily
QHHGWRXVHWKH3\WKRQ,'/(:LWKWKHKHOORS\ƬOHRSHQDOWHULWWR
python3 hello.py
include the following:
This will execute the code we created, which to remind you is:
name=input(“What is your name? “)
a=”Python” print(“Hello,”, name)
b=”is”
c=”cool!”
print(a, b, c)

67(3 Naturally, since this is Python 3 code, using the 67(3 6DYHWKHKHOORS\ƬOHDQGGURSEDFNWRWKH
syntax and layout that’s unique to Python 3, it only command line. Now execute the newly saved
works when you use the python3 command. If you like, try the same code with:
with Python 2 by entering:
python3 hello.py
python hello.py
The result will be the original Python is cool! statement, together
with the added input command asking you for your name, and
displaying it in the command window.

ZZZSFOSXEOLFDWLRQVFRP | 41
Hello, World

Numbers and Expressions


We’ve seen some basic mathematical expressions with Python, simple addition and the
like. Let’s expand on that now and see just how powerful Python is as a calculator. You
can work within the IDLE Shell or in the Editor, whichever you like.

,7o6$//0$7+60$1
<RXFDQJHWVRPHUHDOO\LPSUHVVLYHUHVXOWVZLWKWKHPDWKHPDWLFDOSRZHUVRI3\WKRQDVZLWKPRVWLIQRWDOOSURJUDPPLQJ
ODQJXDJHVPDWKVLVWKHGULYLQJIRUFHEHKLQGWKHFRGH

67(3 2SHQXSWKH*8,YHUVLRQRI3\WKRQDVPHQWLRQHG 67(3 You can use all the usual mathematical operations:
\RXFDQXVHHLWKHUWKH6KHOORUWKH(GLWRU)RUWKH divide, multiply, brackets and so on. Practise with a
time being, you’re going to use the Shell just to warm our maths few, for example:
muscle, which we believe is a small gland located at the back of the
1/2
brain (or not).
6/2
2+2*3
(1+2)+(3*4)

67(3 In the Shell enter the following: 67(3 You’ve no doubt noticed, division produces a
GHFLPDOQXPEHU,Q3\WKRQWKHVHDUHFDOOHGƮRDWV
2+2
RUƮRDWLQJSRLQWDULWKPHWLF+RZHYHULI\RXQHHGDQLQWHJHUDV
54356+34553245
opposed to a decimal answer, then you can use a double slash:
99867344*27344484221
1//2
You can see that Python can handle some quite large numbers.
6//2
And so on.

42 42
| ZZZSFOSXEOLFDWLRQVFRP
Numbers and Expressions

67(3 You can also use an operation to see the remainder 67(3 7KLVZLOOEHGLVSOD\HGDVnEoFRQYHUWLQJWKH
OHIWRYHUIURPGLYLVLRQ)RUH[DPSOH LQWHJHULQWRELQDU\DQGDGGLQJWKHSUHƬ[EWRWKH
IURQW,I\RXZDQWWRUHPRYHWKHESUHƬ[WKHQ\RXFDQXVH
10/3
format(3, ‘b’)
Will display 3.333333333, which is of course 3.3-recurring. If you
now enter: 7KH)RUPDWFRPPDQGFRQYHUWVDYDOXHWKHQXPEHUWRD
IRUPDWWHGUHSUHVHQWDWLRQDVFRQWUROOHGE\WKHIRUPDWVSHFLƬFDWLRQ
10%3
the ‘b’ part.
7KLVZLOOGLVSOD\ZKLFKLVWKHUHPDLQGHUOHIWRYHUIURPGLYLGLQJ
into 3.

67(3 Next up we have the power operator, or 67(3 A Boolean Expression is a logical statement that will
exponentiation if you want to be technical. To work either be true or false. We can use these to compare
out the power of something you can use a double multiplication data and test to see if it’s equal to, less than or greater than. Try this
symbol or double-star on the keyboard: LQD1HZ)LOH
2**3 a = 6
10**10 b = 7
print(1, a == 6)
Essentially, it’s 2x2x2 but we’re sure you already know the basics
print(2, a == 7)
behind maths operators. This is how you would work it out in Python.
print(3, a == 6 and b == 7)
print(4, a == 7 and b == 7)
print(5, not a == 7 and b == 7)
print(6, a == 7 or b == 7)
print(7, a == 7 or b == 6)
print(8, not (a == 7 and b == 6))
print(9, not a == 7 and b == 6)

67(3 Numbers and expressions don’t stop there. Python 67(3 ([HFXWHWKHFRGHIURP6WHSDQG\RXFDQVHHD
has numerous built-in functions to work out sets VHULHVRI7UXHRU)DOVHVWDWHPHQWVGHSHQGLQJRQ
of numbers, absolute values, complex numbers and a host of WKHUHVXOWRIWKHWZRGHƬQLQJYDOXHVDQG,WoVDQH[WHQVLRQRI
PDWKHPDWLFDOH[SUHVVLRQVDQG3\WKDJRUHDQWRQJXHWZLVWHUV)RU what you’ve looked at, and an important part of programming.
example, to convert a number to binary, use:
bin(3)

ZZZSFOSXEOLFDWLRQVFRP 43| 43
Hello, World

8VLQJ&RPPHQWV
:KHQZULWLQJ\RXUFRGHWKHƮRZZKDWHDFKYDULDEOHGRHVKRZWKHRYHUDOOSURJUDP
will operate and so on is all inside your head. Another programmer could follow the
FRGHOLQHE\OLQHEXWRYHUWLPHLWFDQEHFRPHGLƯFXOWWRUHDG

&200(176
3URJUDPPHUVXVHDPHWKRGRINHHSLQJWKHLUFRGHUHDGDEOHE\FRPPHQWLQJRQFHUWDLQVHFWLRQV,IDYDULDEOHLVXVHGWKH
SURJUDPPHUFRPPHQWVRQZKDWLWoVVXSSRVHGWRGRIRUH[DPSOH,WoVMXVWJRRGSUDFWLVH

67(3 Start by creating a new instance of the IDLE Editor 67(3 Resave the code and execute it. You can see that the
)LOH!1HZ)LOH DQGFUHDWHDVLPSOHYDULDEOHDQG output in the IDLE Shell is still the same as before,
print command: despite the extra lines being added. Simply put, the hash symbol (#)
denotes a line of text the programmer can insert to inform them,
a=10
and others, of what’s going on without the user being aware.
print(“The value of A is,”, a)
6DYHWKHƬOHDQGH[HFXWHWKHFRGH

67(3 Running the code will return the line: The value of A 67(3 Let’s assume that the variable A that we’ve created
LVLQWRWKH,'/(6KHOOZLQGRZZKLFKLVZKDWZH is the number of lives in a game. Every time the
expected. Now, add some of the types of comments you’d normally SOD\HUGLHVWKHYDOXHLVGHFUHDVHGE\7KHSURJUDPPHUFRXOG
see within code: insert a routine along the lines of:
# Set the start value of A to 10 a=a-1
a=10 print(“You’ve just lost a life!”)
# Print the current value of A print(“You now have”, a, “lives left!”)
print(“The value of A is,”, a)

44 44
| ZZZSFOSXEOLFDWLRQVFRP
Using Comments

67(3 Whilst we know that the variable A is lives, and 67(3 Inline comments are comments that follow a section
that the player has just lost one, a casual viewer or of code. Take our examples from above, instead of
someone checking the code may not know. Imagine for a moment inserting the code on a separate line, we could use:
that the code is twenty thousand lines long, instead of just our
a=10 # Set the start value of A to 10
seven. You can see how handy comments are.
print(“The value of A is,”, a) # Print the current
value of A
a=a-1 # Player lost a life!
print(“You’ve just lost a life!”)
print(“You now have”, a, “lives left!”) # Inform
player, and display current value of A (lives)

67(3 Essentially, the new code together with comments 67(3 The comment, the hash symbol, can also be used to
could look like: comment out sections of code you don’t want to be
H[HFXWHGLQ\RXUSURJUDP)RULQVWDQFHLI\RXZDQWHGWRUHPRYH
# Set the start value of A to 10
WKHƬUVWSULQWVWDWHPHQW\RXZRXOGXVH
a=10
# Print the current value of A # print(“The value of A is,”, a)
print(“The value of A is,”, a)
# Player lost a life!
a=a-1
# Inform player, and display current value of A
(lives)
print(“You’ve just lost a life!”)
print(“You now have”, a, “lives left!”)

67(3 <RXFDQXVHFRPPHQWVLQGLƪHUHQWZD\V)RU 67(3 You also use three single quotes to comment
example, Block Comments are a large section of out a Block Comment or multi-line section of
text that details what’s going on in the code, such as telling the code comments. Place them before and after the areas you want to
reader what variables you’re planning on using: comment for them to work:
# This is the best game ever, and has been ‘’’
developed by a crack squad of Python experts This is the best game ever, and has been developed
# who haven’t slept or washed in weeks. Despite by a crack squad of Python experts who haven’t
being very smelly, the code at least slept or washed in weeks. Despite being very
# works really well. smelly, the code at least works really well.
’’’

ZZZSFOSXEOLFDWLRQVFRP 45| 45
Hello, World

Working with Variables


We’ve seen some examples of variables in our Python code already but it’s always
worth going through the way they operate and how Python creates and assigns certain
values to a variable.

9$5,2869$5,$%/(6
<RXoOOEHZRUNLQJZLWKWKH3\WKRQ,'/(6KHOOLQWKLVWXWRULDO,I\RXKDYHQoWDOUHDG\RSHQ3\WKRQRUFORVHGRZQWKHSUHYLRXV
,'/(6KHOOWRFOHDUXSDQ\ROGFRGH

67(3 In some programming languages you’re required 67(3 You’ve seen previously that variables can be
to use a dollar sign to denote a string, which is a concatenated using the plus symbol between the
variable made up of multiple characters, such as a name of a person. variable names. In our example we can use: print (name + “:
,Q3\WKRQWKLVLVQoWQHFHVVDU\)RUH[DPSOHLQWKH6KHOOHQWHU “ + title). The middle part between the quotations allows us to
name=”David Hayward” (or use your own name, unless you’re add a colon and a space, as variables are connected without spaces,
also called David Hayward). so we need to add them manually.

67(3 You can check the type of variable in use by 67(3 You can also
issuing the type () command, placing the name of combine variables
the variable inside the brackets. In our example, this would be: ZLWKLQDQRWKHUYDULDEOH)RU
type (name). Add a new string variable: title=”Descended example, to combine both name
from Vikings”. and title variables into a new
variable we use:
character=name + “: “ +
title
Then output the content of the
new variable as:
print (character)
1XPEHUVDUHVWRUHGDVGLƪHUHQW
variables:
age=44
Type (age)
Which, as we know, are integers.

46 46
| ZZZSFOSXEOLFDWLRQVFRP
Working with Variables

67(3 However, you can’t combine both strings and 67(3 This presents a bit of a problem when you want to
integer type variables in the same command, as you work with a number that’s been inputted by the
would a set of similar variables. You need to either turn one into the XVHUDVDJHZRQoWZRUNGXHWREHLQJDVWULQJYDULDEOHDQGDQ
other or vice versa. When you do try to combine both, you get an integer. Instead, you need to enter:
error message:
int(age) + 10
print (name + age)
This will TypeCast the age string into an integer that can be
worked with.

67(3 This is a process known as TypeCasting. The Python 67(3 The use of TypeCasting is also important when
code is: GHDOLQJZLWKƮRDWLQJSRLQWDULWKPHWLFUHPHPEHU
QXPEHUVWKDWKDYHDGHFLPDOSRLQWLQWKHP)RUH[DPSOHHQWHU
print (character + “ is “ + str(age) + “ years
old.”) shirt=19.99
or you can use: Now enter type(shirt) and you’ll see that Python has allocated
WKHQXPEHUDVDnƮRDWoEHFDXVHWKHYDOXHFRQWDLQVDGHFLPDOSRLQW
print (character, “is“, age, “years old.”)
Notice again that in the last example, you don’t need the spaces
between the words in quotes as the commas treat each argument
to print separately.

67(3 Another example of TypeCasting is when you ask for 67(3 :KHQFRPELQLQJLQWHJHUVDQGƮRDWV3\WKRQ
input from the user, such as a name. for example, XVXDOO\FRQYHUWVWKHLQWHJHUWRDƮRDWEXWVKRXOG
enter: the reverse ever be applied it’s worth remembering that Python
GRHVQoWUHWXUQWKHH[DFWYDOXH:KHQFRQYHUWLQJDƮRDWWRDQ
age= input (“How old are you? “)
integer, Python will always round down to the nearest integer,
All data stored from the Input command is stored as a string variable. FDOOHGWUXQFDWLQJLQRXUFDVHLQVWHDGRILWEHFRPHV

ZZZSFOSXEOLFDWLRQVFRP 47| 47
Hello, World

8VHU,QSXW
We’ve seen some basic user interaction with the code from a few of the examples
earlier, so now would be a good time to focus solely on how you would get information
from the user then store and present it.

86(5)5,(1'/<
7KHW\SHRILQSXW\RXZDQWIURPWKHXVHUZLOOGHSHQGJUHDWO\RQWKHW\SHRISURJUDP\RXoUHFRGLQJ)RUH[DPSOHDJDPHPD\
DVNIRUDFKDUDFWHUoVQDPHZKHUHDVDGDWDEDVHFDQDVNIRUSHUVRQDOGHWDLOV

67(3 If it’s not already, open the Python 3 IDLE Shell, 67(3 Now that we have the user’s name stored in a
DQGVWDUWD1HZ)LOHLQWKH(GLWRU/HWoVEHJLQZLWK couple of variables we can call them up whenever
something really simple, enter: we want:
print(“Hello”) print(“Welcome”, firstname, surname, “. I hope
firstname=input(“What is your first name? “) you’re well today.”)
print(“Thanks.”)
surname=input(“And what is your surname? “)

67(3 Save and execute the code, and as you already no 67(3 Run the code and you can see a slight issue, the
doubt suspected, in the IDLE Shell the program will full stop after the surname follows a blank space.
DVNIRU\RXUƬUVWQDPHVWRULQJLWDVWKHYDULDEOHƬUVWQDPHIROORZHG To eliminate that we can add a plus sign instead of the comma in
by your surname; also stored in its own variable (surname). the code:
print(“Welcome”, firstname, surname+“. I hope
you’re well today.”)

48 48
| ZZZSFOSXEOLFDWLRQVFRP
User Input

67(3 You don’t always have to include quoted text within 67(3 What you’ve created here is a condition, which we
WKHLQSXWFRPPDQG)RUH[DPSOH\RXFDQDVNWKH will cover soon. In short, we’re using the input from
user their name, and have the input in the line below: the user and measuring it against a condition. So, if the user enters
David as their name, the guard will allow them to pass unhindered.
print(“Hello. What’s your name?”)
Else, if they enter a name other than David, the guard challenges
name=input()
WKHPWRDƬJKW

67(3 The code from the previous step is often regarded 67(3 Just as you learned previously, any input from a
as being a little neater than having a lengthy user is automatically a string, so you need to apply a
amount of text in the input command, but it’s not a rule that’s set in TypeCast in order to turn it into something else. This creates some
stone, so do as you like in these situations. Expanding on the code, LQWHUHVWLQJDGGLWLRQVWRWKHLQSXWFRPPDQG)RUH[DPSOH
try this:
# Code to calculate rate and distance
print(“Halt! Who goes there?”) print(“Input a rate and a distance”)
name=input() rate = float(input(“Rate: “))

67(3 It’s a good start to a text adventure game, perhaps? 67(3 7RƬQDOLVHWKHUDWHDQGGLVWDQFHFRGHZHFDQDGG
Now you can expand on it and use the raw input
distance = float(input(“Distance:
IURPWKHXVHUWRƮHVKRXWWKHJDPHDOLWWOH
“))
if name==”David”: print(“Time:”, (distance / rate))
print(“Welcome, good sir. You may pass.”)
6DYHDQGH[HFXWHWKHFRGHDQGHQWHUVRPHQXPEHUV8VLQJWKH
else:
ƮRDW LQSXWHOHPHQWZHoYHWROG3\WKRQWKDWDQ\WKLQJHQWHUHGLVD
print(“I know you not. Prepare for battle!”)
ƮRDWLQJSRLQWQXPEHUUDWKHUWKDQDVWULQJ

ZZZSFOSXEOLFDWLRQVFRP 49| 49
Hello, World

&UHDWLQJ)XQFWLRQV
Now that you’ve mastered the use of variables and user input, the next step is to tackle
functions. You’ve already used a few functions, such as the print command but Python
HQDEOHV\RXWRGHƬQH\RXURZQIXQFWLRQV

)81.<)81&7,216
$IXQFWLRQLVDFRPPDQGWKDW\RXHQWHULQWR3\WKRQWRGRVRPHWKLQJ,WoVDOLWWOHSLHFHRIVHOIFRQWDLQHGFRGHWKDWWDNHVGDWD
ZRUNVRQLWDQGWKHQUHWXUQVWKHUHVXOW

67(3 It’s not just data that a function works on. They can 67(3 You can pass variables through functions in much
do all manner of useful things in Python, such as the same manner. Let’s assume you want the
sort data, change items from one format to another and check the number of letters in a person’s surname, you could use the following
length or type of items. Basically, a function is a short word that’s code (enter the text editor for this example):
IROORZHGE\EUDFNHWV)RUH[DPSOHlen(), list() or type().
name=input (“Enter your surname: “)
count=len(name)
print (“Your surname has“, count, “letters in
it.”)
3UHVV)DQGVDYHWKHFRGHWRH[HFXWHLW

67(3 A function takes data, usually a variable, works on 67(3 Python has tens of functions built into it, far too
it depending on what the function is programmed many to get into in the limited space available here.
to do and returns the end value. The data being worked on goes However, to view the list of built-in functions available to Python 3,
inside the brackets, so if you wanted to know how many letters navigate to www.docs.python.org/3/library/functions.html. These
are in the word antidisestablishmentarianism, then you’d enter: DUHWKHSUHGHƬQHGIXQFWLRQVEXWVLQFHXVHUVKDYHFUHDWHGPDQ\
len(“antidisestablishmentarianism”)DQGWKHQXPEHU more, they’re not the only ones available.
would return.

50 50
| ZZZSFOSXEOLFDWLRQVFRP
Creating Functions

67(3 Additional functions can be added to Python 67(3 To use a function from a module enter the name of
through modules. Python has a vast range of the module followed by a full stop, then the name
modules available that can cover numerous programming duties. RIWKHIXQFWLRQ)RULQVWDQFHXVLQJWKH0DWKPRGXOHVLQFH\RXoYH
7KH\DGGIXQFWLRQVDQGFDQEHLPSRUWHGDVDQGZKHQUHTXLUHG)RU just imported it into Python, you can utilise the square root function.
example, to use advanced mathematics functions enter: To do so, enter:
import math math.sqrt(16)
Once entered, you have access to all the Math module functions. You can see that the code is presented as module.function(data).

)25*,1*)81&7,216
7KHUHDUHPDQ\GLƪHUHQWIXQFWLRQV\RXFDQLPSRUWFUHDWHGE\RWKHU3\WKRQSURJUDPPHUVDQG\RXZLOOXQGRXEWHGO\FRPH
DFURVVVRPHH[FHOOHQWH[DPSOHVLQWKHIXWXUH\RXFDQDOVRFUHDWH\RXURZQZLWKWKHGHIFRPPDQG

67(3 Choose File > New File to enter the editor, let’s 67(3 7RPRGLI\LWIXUWKHUGHOHWHWKH+HOOR p'DYLGq OLQH
create a function called Hello, that greets a user. the last line in the script and press Ctrl+S to save
Enter: WKHQHZVFULSW&ORVHWKH(GLWRUDQGFUHDWHDQHZƬOH )LOH!1HZ
File). Enter the following:
def Hello():
print (“Hello”) from Hello import Hello
Hello() Hello(“David”)
Press F5 to save and run the script. You can see Hello in the Shell, Press F5 to save and execute the code.
type in Hello() and it returns the new function.

67(3 Let’s now expand the function to accept a 67(3 What you’ve just done is import the Hello function
variable, the user’s name for example. Edit your from the saved Hello.py program and then used it
script to read: to say hello to David. This is how modules and functions work: you
import the module then use the function. Try this one, and modify
def Hello(name):
it for extra credit:
print (“Hello”, name)
def add(a, b):
Hello(“David”)
result = a + b
This will now accept the variable name, otherwise it prints Hello
return result
'DYLG,QWKH6KHOOHQWHUQDPH p%REq WKHQ+HOOR QDPH <RXU
function can now pass variables through it.

ZZZSFOSXEOLFDWLRQVFRP | 51
Hello, World

Conditions and Loops


Conditions and loops are what make a program interesting; they can be simple or rather
complex. How you use them depends greatly on what the program is trying to achieve;
they could be the number of lives left in a game or just displaying a countdown.

758(&21',7,216
.HHSLQJFRQGLWLRQVVLPSOHWREHJLQZLWKPDNHVOHDUQLQJWRSURJUDPDPRUHHQMR\DEOHH[SHULHQFH/HWoVVWDUWWKHQE\FKHFNLQJ
LIVRPHWKLQJLV758(WKHQGRLQJVRPHWKLQJHOVHLILWLVQoW

67(3 Let’s create a new Python program that will ask 67(3 Now you can use an if statement to check if the
the user to input a word, then check it to see if it’s word_length variable is equal to four and print a
DIRXUOHWWHUZRUGRUQRW6WDUWZLWK)LOH!1HZ)LOHDQGEHJLQZLWK friendly conformation if it applies to the rule:
the input variable:
word=input(“Please enter a four-letter word: “)
word=input(“Please enter a four-letter word: “) word_length=len(word)
if word_length == 4:
print (word, “is a four-letter word. Well done.”)
The double equal sign (==) means check if something is equal to
something else.

67(3 Now we can create a new variable, then use the len 67(3 7KHFRORQDWWKHHQGRI,)WHOOV3\WKRQWKDWLIWKLV
function and pass the word variable through it to statement is true do everything after the colon
get the total number of letters the user has just entered: that’s indented. Next, move the cursor back to the beginning of
the Editor:
word=input(“Please enter a four-letter word: “)
word_length=len(word) word=input(“Please enter a four-letter word: “)
word_length=len(word)
if word_length == 4:
print (word, “is a four-letter word. Well
done.”)
else:
print (word, “is not a four-letter word.”)

52 52
| ZZZSFOSXEOLFDWLRQVFRP
Conditions and Loops

67(3 3UHVV)DQGVDYHWKHFRGHWRH[HFXWHLW(QWHU 67(3 Now expand the code to include another conditions.
a four-letter word in the Shell to begin with, you Eventually, it could become quite complex. We’ve
should have the returned message that it’s the word is four letters. added a condition for three-letter words:
1RZSUHVV)DJDLQDQGUHUXQWKHSURJUDPEXWWKLVWLPHHQWHUD
word=input(“Please enter a four-letter word: “)
ƬYHOHWWHUZRUG7KH6KHOOZLOOGLVSOD\WKDWLWoVQRWDIRXUOHWWHUZRUG
word_length=len(word)
if word_length == 4:
print (word, “is a four-letter word. Well
done.”)
elif word_length == 3:
print (word, “is a three-letter word. Try again.”)
else:
print (word, “is not a four-letter word.”)

/2236
$ORRSORRNVTXLWHVLPLODUWRDFRQGLWLRQEXWWKH\DUHVRPHZKDWGLƪHUHQWLQWKHLURSHUDWLRQ$ORRSZLOOUXQWKURXJKWKHVDPH
EORFNRIFRGHDQXPEHURIWLPHVXVXDOO\ZLWKWKHVXSSRUWRIDFRQGLWLRQ

67(3 Let’s start with a simple While statement. Like IF, 67(3 The For loop is another example. For is used to
this will check to see if something is TRUE, then run loop over a range of data, usually a list stored as
the indented code: variables inside square brackets. For example:
x = 1 words=[“Cat”, “Dog”, “Unicorn”]
while x < 10:
for word in words:
print (x)
print (word)
x = x + 1

67(3 7KHGLƪHUHQFHEHWZHHQLIDQGZKLOHLVZKHQZKLOH 67(3 The For loop can also be used in the countdown
gets to the end of the indented code, it goes back example by using the range function:
and checks the statement is still true. In our example x is less than
for x in range (1, 10):
10. With each loop it prints the current value of x, then adds one to
print (x)
that value. When x does eventually equal 10 it stops.
The x=x+1 part isn’t needed here because the range function
FUHDWHVDOLVWEHWZHHQWKHƬUVWDQGODVWQXPEHUVXVHG

53| 53
Hello, World

Python Modules
We’ve mentioned modules previously, (the Math module) but as modules are such a
large part of getting the most from Python, it’s worth dedicating a little more time to
them. In this instance we’re using the Windows version of Python 3.

0$67(5,1*02'8/(6
7KLQNRIPRGXOHVDVDQH[WHQVLRQWKDWoVLPSRUWHGLQWR\RXU3\WKRQFRGHWRHQKDQFHDQGH[WHQGLWVFDSDELOLWLHV7KHUHDUH
FRXQWOHVVPRGXOHVDYDLODEOHDQGDVZHoYHVHHQ\RXFDQHYHQPDNH\RXURZQ

67(3 Although good, the built-in functions within Python 67(3 The result is an error in the IDLE Shell, as the
are limited. The use of modules, however, allows us Pygame module isn’t recognised or installed in
to make more sophisticated programs. As you are aware, modules Python. To install a module we can use PIP (Pip Installs Packages).
are Python scripts that are imported, such as import math. Close down the IDLE Shell and drop into a command prompt or
Terminal session. At an elevated admin command prompt, enter:
pip install pygame

67(3 Some modules, especially on the Raspberry Pi, 67(3 The PIP installation requires an elevated status
are included by default, the Math module being a GXHLWLQVWDOOLQJFRPSRQHQWVDWGLƪHUHQWORFDWLRQV
prime example. Sadly, other modules aren’t always available. A good Windows users can search for CMD via the Start button and right-
example on non-Pi platforms is the Pygame module, which contains click the result then click Run as Administrator. Linux and Mac users
many functions to help create games. Try: import pygame. can use the Sudo command, with sudo pip install package.

54 54
| ZZZSFOSXEOLFDWLRQVFRP
Python Modules

67(3 Close the command prompt or Terminal and 67(3 Multiple modules can be imported within your code.
relaunch the IDLE Shell. When you now enter: To extend our example, use:
import pygame, the module will be imported into the code
import random
ZLWKRXWDQ\SUREOHPV<RXoOOƬQGWKDWPRVWFRGHGRZQORDGHGRU
import math
copied from the Internet will contain a module, mainstream of
unique, these are usually the source of errors in execution due to for I in range(5):
them being missing. print(random.randint(1, 25))
print(math.pi)

67(3 The modules contain the extra code needed to 67(3 The result is a string of random numbers followed
achieve a certain result within your own code, as by the value of Pi as pulled from the Math module
ZHoYHSUHYLRXVO\H[SHULPHQWHGZLWK)RUH[DPSOH using the print(math.pi) function. You can also pull in certain
functions from a module by using the from and import commands,
import random
such as:
%ULQJVLQWKHFRGHIURPWKH5DQGRP1XPEHU*HQHUDWRUPRGXOH
from random import randint
You can then use this module to create something like:
for i in range(5):
for i in range(10):
print(randint(1, 25))
print(random.randint(1, 25))

67(3 This code, when saved and executed, will display ten 67(3 This helps create a more streamlined approach to
UDQGRPQXPEHUVIURPWR<RXFDQSOD\DURXQG programming. You can also use import module*,
with the code to display more or less, and from a great or lesser ZKLFKZLOOLPSRUWHYHU\WKLQJGHƬQHGZLWKLQWKHQDPHGPRGXOH
UDQJH)RUH[DPSOH However, it’s often regarded as a waste of resources but it works
QRQHWKHOHVV)LQDOO\PRGXOHVFDQEHLPSRUWHGDVDOLDVHV
import random
import math as m
for i in range(25):
print(random.randint(1, 100)) print(m.pi)
Of course, adding comments helps to tell others what’s going on.

ZZZSFOSXEOLFDWLRQVFRP 55| 55
Hello, World

Python Errors
It goes without saying that you’ll eventually come across an error in your code, where
Python declares it’s not able to continue due to something being missed out, wrong or
VLPSO\XQNQRZQ%HLQJDEOHWRLGHQWLI\WKHVHHUURUVPDNHVIRUDJRRGSURJUDPPHU

'(%8**,1*
(UURUVLQFRGHDUHFDOOHGEXJVDQGDUHSHUIHFWO\QRUPDO7KH\FDQRIWHQEHHDVLO\UHFWLƬHGZLWKDOLWWOHSDWLHQFH7KHLPSRUWDQW
WKLQJLVWRNHHSORRNLQJH[SHULPHQWLQJDQGWHVWLQJ(YHQWXDOO\\RXUFRGHZLOOEHEXJIUHH

67(3 &RGHLVQoWDVƮXLGDVWKHZULWWHQZRUGQRPDWWHU 67(3 Thankfully Python is helpful when it comes to


how good the programming language is. Python is displaying error messages. When you receive an
certainly easier than most languages but even it is prone to some HUURULQUHGWH[WIURPWKH,'/(6KHOOLWZLOOGHƬQHWKHHUURULWVHOI
annoying bugs. The most common are typos by the user and whilst along with the line number where the error has occurred. Whilst in
HDV\WRƬQGLQVLPSOHGR]HQOLQHFRGHLPDJLQHKDYLQJWRGHEXJ the IDLE Editor this is a little daunting for lots of code; text editors
multi-thousand line code. help by including line numbering.

67(3 The most common of errors is the typo, as we’ve 67(3 Syntax errors are probably the second most
mentioned. The typos are often at the command common errors you’ll come across as a programmer.
level: mistyping the print command for example. However, they also Even if the spelling is correct, the actual command itself is wrong.
occur when you have numerous variables, all of which have lengthy In Python 3 this often occurs when Python 2 syntaxes are applied.
names. The best advice is to simply go through the code and check The most annoying of these is the print function. In Python 3 we use
your spelling. print(“words”), whereas Python2 uses print “words”.

56 56
| ZZZSFOSXEOLFDWLRQVFRP
Python Errors

67(3 Pesky brackets are also a nuisance in programming 67(3 An excellent way to check your code step-by-step
errors, especially when you have something like: is to use Python Tutor’s Visualise web page, found
DWZZZS\WKRQWXWRUFRPYLVXDOL]HKWPOPRGH HGLW6LPSO\
print(balanced_check(input()))
paste your code into the editor and click the Visualise Execution
Remember that for every ‘(‘ there must be an equal number of ‘)’. button to run the code line-by-line. This helps to clear bugs and
any misunderstandings.

67(3 There are thousands of online Python resources, 67(3 Planning makes for good code. Whilst a little old
code snippets and lengthy discussions across forums school, it’s a good habit to plan what your code
RQKRZEHVWWRDFKLHYHVRPHWKLQJ:KLOVWSHUFHQWRILWLVJRRG will do before sitting down to type it out. List the variables that will
code, don’t always be lured into copying and pasting random code be used and the modules too; then write out a script for any user
into your editor. More often than not, it won’t work and the worst interaction or outputs.
part is that you haven’t learnt anything.

67(3 Indents are a nasty part of Python programming 67(3 Purely out of interest, the word debugging in
that a lot of beginners fall foul of. Recall the If loop FRPSXWLQJWHUPVFRPHVIURP$GPLUDO*UDFH
from the Conditions and Loops section, where the colon means Hopper, who back in the ‘40s was working on a monolithic Harvard
everything indented following the statement is to be executed as Mark II electromechanical computer. According to legend Hopper
long as it’s true? Missing the indent, or having too much of indent, found a moth stuck in a relay, thus stopping the system from
will come back with an error. working. Removal of the moth was hence called debugging.

ZZZSFOSXEOLFDWLRQVFRP 57| 57
Hello, World

Combining What
<RX.QRZ6R)DU
We’ve reached the end of this section so let’s take a moment to combine everything
we’ve looked at so far, and apply it to writing a piece of code. This code can then be
used and inserted into your own programs in future; either part of it or as a whole.

3/$<,1*:,7+3,
)RUWKLVH[DPSOHZHoUHJRLQJWRFUHDWHDSURJUDPWKDWZLOOFDOFXODWHWKHYDOXHRI3LWRDVHWQXPEHURIGHFLPDOSODFHVDV
GHVFULEHGE\WKHXVHU,WFRPELQHVPXFKRIZKDWZHoYHOHDUQWDQGDOLWWOHPRUH

67(3 6WDUWE\RSHQLQJ3\WKRQDQGFUHDWLQJD1HZ)LOHLQ 67(3 7KHSUHYLRXVVWHSGHƬQHVWKHUXOHVWKDWPDNH


WKH(GLWRU)LUVWZHQHHGWRJHWKROGRIDQHTXDWLRQ up the algorithm and creates the string that will
that can accurately calculate Pi without rendering the computer’s eventually display the value of Pi, according the Chudnovsky
&38XVHOHVVIRUVHYHUDOPLQXWHV7KHUHFRPPHQGHGFDOFXODWLRQ brothers’ algorithm. You have no doubt already surmised that it
used in such circumstances is the Chudnovsky Algorithm, you would be handy to actually output the value of Pi to the screen. To
FDQƬQGPRUHLQIRUPDWLRQDERXWLWDWHQZLNLSHGLDRUJZLNL rectify that you can add:
Chudnovsky_algorithm.
print(calc(1))

67(3 You can utilise the Chudnovsky Algorithm to create


67(3 You can save and execute the code at this point if
your own Python script based on the calculation.
you like. The output will print the value of Pi to 27
Begin by importing some important modules and functions within
decimal places: . Whilst pretty
the modules:
impressive on its own, you want some user interaction, to ask the
from decimal import Decimal, getcontext user as to how many places Pi should be calculated.
import math
This uses the decimal and getcontext functions from the Decimal 67(3 You can insert an input line before the Pi calculation
module, both of which deal with large decimal place numbers and Def command. It needs to be an integer, as it will
naturally the Math module. otherwise default to a string. We can call it numberofdigits and use
the getcontext function:

67(3 Now you can insert the Pi calculation algorithm numberofdigits = int(input(“please enter the
part of the code. This is a version of the number of decimal place to calculate Pi to: “))
Chudnovsky Algorithm: getcontext().prec = numberofdigits
def calc(n):
t = Decimal(0)
pi = Decimal(0)
deno = Decimal(0)
k = 0
for k in range(n):
t = (Decimal(-1)**k)*(math.factorial
(Decimal(6)*k))*(13591409 +545140134*k)
deno = math.factorial(3*k)*(math.
factorial(k)**Decimal(3))*(640320**(3*k))
pi += Decimal(t)/Decimal(deno)
pi = pi * Decimal(12)/
Decimal(640320**Decimal(1.5))
pi = 1/pi
return str(pi)

58 58
| ZZZSFOSXEOLFDWLRQVFRP
Combining What You Know So Far

67(3 You can execute the code now and it asks the user 67(3 Now we need to import the Colorama module
how many decimal places they want to calculate Pi ZKLFKZLOORXWSXWWH[WLQGLƪHUHQWFRORXUV DORQJ
WRRXWSXWWLQJWKHUHVXOWLQWKH,'/(6KHOO7U\LWZLWKSODFHV ZLWKWKH)RUHIXQFWLRQ ZKLFKGLFWDWHVWKHIRUHJURXQGLQNFRORXU 
but don’t go too high or else your computer will be locked up in and the Time module to start a virtual stopwatch to see how long
calculating Pi. our calculations take:
import time
67(3 Part of programming is import colorama
being able to modify code, from colorama import Fore
making it more presentable. Let’s include
an element that times how long it takes our
computer to calculate the Pi decimal places
DQGSUHVHQWWKHLQIRUPDWLRQLQDGLƪHUHQW
FRORXU)RUWKLVGURSLQWRWKHFRPPDQGOLQH
and import the Colorama module (RPi users
already have it installed):
pip install colorama

67(3 7RƬQLVKRXUFRGHZHQHHGWRLQLWLDOLVHWKH t = Decimal(0)


Colorama module and start the time function at pi = Decimal(0)
WKHSRLQWZKHUHWKHFDOFXODWLRQVWDUWVDQGZKHQLWƬQLVKHV7KHHQG deno = Decimal(0)
result is a coloured ink displaying how long the process took (in the k = 0
Terminal or command line): for k in range(n):
t = (Decimal(-1)**k)*(math.
from decimal import Decimal, getcontext
factorial(Decimal(6)*k))*(13591409+545140134*k)
import math
deno = math.factorial(3*k)*(math.
import time
factorial(k)**Decimal(3))*(640320**(3*k))
import colorama
pi += Decimal(t)/Decimal(deno)
from colorama import Fore
pi = pi * Decimal(12)/
colorama.init()
Decimal(640320**Decimal(1.5))
numberofdigits = int(input(“please enter the number pi = 1/pi
of decimal places to calculate Pi to: “)) return str(pi)
getcontext().prec = numberofdigits
print(calc(1))
start_time = time.time() print(Fore.RED + “\nTime taken:”, time.time() -
def calc(n): start_time)

ZZZSFOSXEOLFDWLRQVFRP 59| 59
Hello, World

3\WKRQLQ)RFXV
Stitching Black Holes
2QHRIWKHELJJHVWVFLHQWLƬFHQJLQHHULQJDQGVSDFHEDVHGSURMHFWVFDPHWRDKHDGLQ
UHYHDOLQJKXPDQLW\oVƬUVWJOLPSVHDWWKHXQLYHUVHoVPRVWHOXVLYHREMHFWDEODFN
KROH%XWZKDWoVWKDWJRWWRGRZLWK3\WKRQ"
,PDJLQJDEODFNKROHLVSUHWW\GLƯFXOW7KHYHU\QDWXUHRID in curved spacetime predicts that event horizons emit Hawking
black hole means that nothing can escape its immense gravitational radiation, with the same spectrum as a black body of a temperature
ƬHOGHYHQOLJKWLWVHOI7RTXRWHWKH:LNLSHGLDHQWU\IRUDEODFNKROH inversely proportional to its mass. This temperature is on the order
of billionths of a kelvin for black holes of stellar mass, making it
p$EODFNKROHLVDUHJLRQRIVSDFHWLPHH[KLELWLQJJUDYLWDWLRQDO essentially impossible to observe.”
acceleration so strong that nothing—no particles or even
electromagnetic radiation such as light—can escape from it. The Not that long ago a black hole was just a collection of theories
WKHRU\RIJHQHUDOUHODWLYLW\SUHGLFWVWKDWDVXƯFLHQWO\FRPSDFWPDVV and mathematics written down on paper, speculated only by the
can deform spacetime to form a black hole. The boundary of the EULJKWHVWPLQGVRIRXUWLPH+RZHYHUDVZLWKPRVWWKLQJVVFLHQWLƬF
region from which no escape is possible is called the event horizon. our understanding of the universe and our abilities to read it have
$OWKRXJKWKHHYHQWKRUL]RQKDVDQHQRUPRXVHƪHFWRQWKHIDWHDQG greatly improved and, with the culmination of years of
circumstances of an object crossing it, no locally detectable features hard work by a collaboration of observatories,
appear to be observed. In many ways, a black hole acts like an ideal VFLHQWLVWVDQGHQJLQHHUVZHJRWRXUƬUVW
EODFNERG\DVLWUHƮHFWVQROLJKW0RUHRYHUTXDQWXPƬHOGWKHRU\ image of a black hole.

(9(17+25,=217(/(6&23(
One of the problems regarding the imaging of such an object is
angular resolution. In Astronomy, the size of the objects in the night
sky is referred to by the amount of the sky they take up - units of
arc. An arc, or arc second, is a measurement (1/3600 of a degree)
that describes the size of an angle in degrees, designated by the
symbol °. A full circle is divided into 360° and a right-angle measures
90°. One degree can be divided into 60 arcminutes (abbreviated 60
arcmin or 60’). An arcminute can also be divided into 60 arcseconds
DEEUHYLDWHGDUFVHFRUq {

For example, looking at the moon, which is roughly 31 arcminutes,


imagine drawing a line from you to one side of the moon and
another to the opposite side of the moon, the angle between the
two lines is the angular size, or angular resolution.

The black hole at the centre of the Messier 87 galaxy, the one that
was imaged, is 55 million light years from Earth and has an angular
size of 40 microarc seconds, or one millionth of an arcsecond. So,
in order to see it, we would need a telescope with a diameter of
around 8Km, which simply isn’t possible as a single unit.

This is where the Event Horizon Telescope project comes into play.
Using a network of eight radio telescopes, scientists were able to
take images of the black hole over a period of around six months.
Critically timed, using atomic clocks, the telescopes imaged the area
of sky containing the black hole and collected the data, swapping
from one telescope array to the next as the Earth rotated.

60 60
| ZZZSFOSXEOLFDWLRQVFRP
3\WKRQLQ)RFXV6WLWFKLQJ%ODFN+ROHV

%,*'$7$$1'3<7+21 5(68/76
This data was then collated across all the telescope arrays to the The end result is, of course, the image of the black hole at the centre
tune of over a thousand hard drives, which came to an astonishing 5 of the M87 galaxy that’s surrounded by a ring of burning gasses. The
Petabytes of raw data. The problem now was collating all that data resolution isn’t great, as the team have since admitted, but, as they
into a workable form and presenting it as an image. also state, give it a couple of years and they’ll be able to increase the
LPDJHUHVROXWLRQVLJQLƬFDQWO\
.DWLH%RXPDQD3K'LQHOHFWULFDO
engineering and computer science All this is thanks to some clever Python code and some very brilliant
from MIT, was pivotal in creating the scientists and engineers.
Python code that was able to stitch
all that data together and form the
eventual, historic image of a black hole.

%RXPDQXVHGDQXPEHURI3\WKRQ
libraries to achieve the result, Numpy,
Scipy, Pandas, Jupyter, Matplotlib
and Astropy, plus some unique custom Python code – which can be
found on Github at KWWSVJLWKXEFRPDFKDHOHKWLPDJLQJ.

| 61
Working with Data

62 62
| ZZZSFOSXEOLFDWLRQVFRP
Working with Data

Data is everything; it can topple governments, change election


results, and tell us the secrets of the universe. Over these coming
pages we look at how you can create lists, tuples, dictionaries and
multi-dimensional lists, and then how you can use them to forge
exciting and useful programs.
In addition, you will learn how you can use the date and time
functions, write to OHVWR\RXUV\VWHPDQGHYHQFUHDWHgraphical
user interfaces that will take your coding skills to new levels and into
new project ideas.

ZZZSFOSXEOLFDWLRQVFRP 63| 63
Working with Data

Lists
Lists are one of the most common types of data structures you will come across in
Python. A list is simply a collection of items, or data if you prefer, that can be accessed
as a whole, or individually if wanted.

WORKING WITH LISTS


Lists are extremely handy in Python. A list can be strings, integers and also variables. You can even include functions in lists,
and lists within lists.

STEP 1 A list is a sequence of data values called items. You STEP 3 You can also access, or index, the last item in a list by
create the name of your list followed by an equals using the minus sign before the item number [-1],
sign, then square brackets and the items separated by commas; or the second to last item with [-2] and so on. Trying to reference an
note that strings use quotes: item that isn’t in the list, such as [10] will return an error:
numbers = [1, 4, 7, 21, 98, 156] numbers[-1]
mythical_creatures – [“Unicorn”, “Balrog”, mythical_creatures[-4]
“Vampire”, “Dragon”, “Minotaur”]

STEP 2 2QFH\RXoYHGHƬQHG\RXUOLVW\RXFDQFDOOHDFK STEP 4 Slicing is similar to indexing but you can retrieve
by referencing its name, followed by a number. Lists multiple items in a list by separating item numbers
VWDUWWKHƬUVWLWHPHQWU\DVIROORZHGE\DQGVRRQ with a colon. For example:
For example:
numbers[1:3]
numbers
Will output the 4 and 7, being item numbers 1 and 2. Note that the
To call up the entire contents of the list. returned values don’t include the second index position (as you
ZRXOGQXPEHUV>@WRUHWXUQDQG 
numbers[3]
To call the third from zero item in the list (21 in this case).

64 64
| ZZZSFOSXEOLFDWLRQVFRP
Lists

STEP 5 You can update items within an existing list, remove STEP 8 You can view what can be done with lists by entering
items and even join lists together. For example, to dir(list) into the Shell. The output is the available
join two lists you can use: functions, for example, insert and pop are used to add and remove
items at certain positions. To insert the number 62 at item index 4:
everything = numbers + mythical_creatures
numbers.insert(4, 62)
Then view the combined list with:
To remove it:
everything
numbers.pop(4)

STEP 6 Items can be added to a list by entering: STEP 9 You also use the list function to break a string down
into its components. For example:
numbers=numbers+[201]
list(“David”)
Or for strings:
Breaks the name David into ‘D’, ‘a’, ‘v’, ‘i’, ‘d’. This can then be passed
mythical_creatres=mythical_creatures+[“Griffin”]
to a new list:
Or by using the append function:
name=list(“David Hayward”)
mythical_creatures.append(“Nessie”) name
numbers.append(278) age=[44]
user = name + age
user

STEP 7 5HPRYDORILWHPVFDQEHGRQHLQWZRZD\V7KHƬUVW STEP 10 Based on that, you can create a program to store
is by the item number: someone’s name and age as a list:
del numbers[7] name=input(“What’s your name? “)
lname=list(name)
Alternatively, by item name:
age=int(input(“How old are you: “))
mythical_creatures.remove(“Nessie”) lage=[age]
user = lname + lage
The combined name and age list is called user, which can be called
by entering user into the Shell. Experiment and see what you can do.

ZZZSFOSXEOLFDWLRQVFRP 65| 65
Working with Data

Tuples
Tuples are very much identical to lists. However, where lists can be updated, deleted or
changed in some way, a tuple remains a constant. This is called immutable and they’re
SHUIHFWIRUVWRULQJƬ[HGGDWDLWHPV

THE IMMUTABLE TUPLE


Reasons for having tuples vary depending on what the program is intended to do. Normally, a tuple is reserved for something
special but they’re also used for example, in an adventure game, where non-playing character names are stored.

STEP 1 A tuple is created the same way as a list but in this STEP 3 You can create grouped tuples into lists that contain
instance you use curved brackets instead of square multiple sets of data. For instance, here is a tuple
brackets. For example: called NPC (Non-Playable Characters) containing the character name
and their combat rating for an adventure game:
months=(“January”, “February”, “March”, “April”,
“May”, “June”) NPC=[(“Conan”, 100), (“Belit”, 80), (“Valeria”,
months 95)]

STEP 2 Just as with lists, the items within a named tuple can STEP 4 Each of these data items can be accessed as a
be indexed according to their position in the data whole by entering NPC into the Shell; or they can be
range, i.e.: indexed according to their position NPC[0]. You can also index the
individual tuples within the NPC list:
months[0]
months[5] NPC[0][1]
However, any attempt at deleting or adding to the tuple will result Will display 100.
in an error in the Shell.

66 66
| ZZZSFOSXEOLFDWLRQVFRP
Tuples

STEP 5 It’s worth noting that when referencing multiple STEP 8 Now unpack the tuple into two
WXSOHVZLWKLQDOLVWWKHLQGH[LQJLVVOLJKWO\GLƪHUHQW corresponding variables:
from the norm. You would expect the 95 combat rating of the
(name, combat_rating)=NPC
character Valeria to be NPC[4][5], but it’s not. It’s actually:
You can now check the values by entering name and combat_rating.
NPC[2][1]

STEP 6 This means of course that the indexing follows thus: STEP 9 Remember, as with lists, you can also index tuples
using negative numbers which count backwards
0 1, 1
from the end of the data list. For our example, using the tuple with
0, 0 2
multiple data items, you would reference the Valeria character with:
0, 1 2, 0
1 2,1 NPC[2][-0]
1, 0
Which as you can imagine, gets a little confusing when you’ve got a
lot of tuple data to deal with.

STEP 7 Tuples though utilise a feature called unpacking, STEP 10 <RXFDQXVHWKHPD[DQGPLQIXQFWLRQVWRƬQGWKH


where the data items stored within a tuple are highest and lowest values of a tuple composed of
assigned variables. First create the tuple with two items (name and numbers. For example:
combat rating):
numbers=(10.3, 23, 45.2, 109.3, 6.1, 56.7, 99)
NPC=(“Conan”, 100)
7KHQXPEHUVFDQEHLQWHJHUVDQGƮRDWV7RRXWSXWWKHKLJKHVWDQG
lowest, use:
print(max(numbers))
print(min(numbers))

ZZZSFOSXEOLFDWLRQVFRP 67| 67
Working with Data

Dictionaries
/LVWVDUHH[WUHPHO\XVHIXOEXWGLFWLRQDULHVLQ3\WKRQDUHE\IDUWKHPRUHWHFKQLFDOZD\
RIGHDOLQJZLWKGDWDLWHPV7KH\FDQEHWULFN\WRJHWWRJULSVZLWKDWƬUVWEXW\RXoOOVRRQ
be able to apply them to your own code.

KEY PAIRS
A dictionary is like a list but instead each data item comes as a pair, these are known as Key and Value. The Key part must be
unique and can either be a number or string whereas the Value can be any data item you like.

STEP 1 Let’s say you want to create a phonebook in Python. STEP 3 As with lists and tuples, you can check the contents
You would create the dictionary name and enter of a dictionary by giving the dictionary a name:
the data in curly brackets, separating the key and value by a colon phonebook, in this example. This will display the data items you’ve
Key:Value. For example: entered in a similar fashion to a list, which you’re no doubt familiar
with by now.
phonebook={“Emma”: 1234, “Daniel”: 3456, “Hannah”:
6789}

STEP 2 Just as with most lists, tuples and so on, strings STEP 4 7KHEHQHƬWRIXVLQJDGLFWLRQDU\LVWKDW\RX
need be enclosed in quotes (single or double), can enter the key to index the value. Using the
whilst integers can be left open. Remember that the value can be phonebook example from the previous steps, you can enter:
either a string or an integer, you just need to enclose the relevant
phonebook[“Emma”]
one in quotes:
phonebook[“Hannah”]
phonebook2={“David”: “0987 654 321”}

68 68
| ZZZSFOSXEOLFDWLRQVFRP
Dictionaries

STEP 5 Adding to a dictionary is easy too. You can include STEP 8 1H[W\RXQHHGWRGHƬQHWKHXVHULQSXWVDQG
a new data item entry by adding the new key and variables: one for the person’s name, the other
value items like: for their phone number (let’s keep it simple to avoid lengthy
Python code):
phonebook[“David”] = “0987 654 321”
phonebook name=input(“Enter name: “)
number=int(input(“Enter phone number: “))

STEP 6 You can also remove items from a dictionary by STEP 9 Note we’ve kept the number as an integer instead
issuing the del command followed by the item’s of a string, even though the value can be both
key; the value will be removed as well, since both work as a pair of an integer or a string. Now you need to add the user’s inputted
data items: variables to the newly created blank dictionary. Using the same
process as in Step 5, you can enter:
del phonebook[“David”]
phonebook[name] = number

STEP 7 Taking this a step further, how about creating a STEP 10 Now when you save and execute the code, Python
piece of code that will ask the user for the dictionary will ask for a name and a number. It will then insert
key and value items? Create a new Editor instance and start by those entries into the phonebook dictionary, which you can test by
coding in a new, blank dictionary: entering into the Shell:
phonebook={} phonebook
phonebook[“David”]
If the number needs to contain spaces you need to make it a string,
so remove the int part of the input.

ZZZSFOSXEOLFDWLRQVFRP 69| 69
Working with Data

Splitting and
Joining Strings
When dealing with data in Python, especially from a user’s input, you will undoubtedly
come across long sets of strings. A useful skill to learn in Python programming is being
able to split those long strings for better readability.

STRING THEORIES
You’ve already looked at some list functions, using .insert, .remove, and .pop but there are also functions that can be applied
to strings.

STEP 1 The main tool in the string function arsenal is .split(). STEP 3 Note that the text.split part has the brackets,
With it you’re able to split apart a string of data, quotes, then a space followed by closing quotes
based on the argument within the brackets. For example, here’s a and brackets. The space is the separator, indicating that each list
string with three items, each separated by a space: item entry is separated by a space. Likewise, CSV (Comma Separated
Value) content has a comma, so you’d use:
text=”Daniel Hannah Emma”
text=”January,February,March,April,May,June”
months=text.split(“,”)
months

STEP 2 Now let’s turn the string into a list and split the STEP 4 You’ve previously seen how you can split a string
content accordingly: into individual letters as a list, using a name:
names=text.split(“ “) name=list(“David”)
name
Then enter the name of the new list, names, to see the three items.
The returned value is ‘D’, ‘a’, ‘v’, ‘i’, ‘d’. Whilst it may seem a little
useless under ordinary circumstances, it could be handy for creating
a spelling game for example.

70 70
| ZZZSFOSXEOLFDWLRQVFRP
Splitting and Joining Strings

STEP 5 The opposite of the .split function is .join, where STEP 8 As with the .split function, the separator doesn’t
you will have separate items in a string and can join have to be a space, it can also be a comma, a full
them all together to form a word or just a combination of items, stop, a hyphen or whatever you like:
depending on the program you’re writing. For instance:
colours=[“Red”, “Green”, “Blue”]
alphabet=””.join([“a”,”b”,”c”,”d”,”e”]) col=”,”.join(colours)
alphabet col
This will display ‘abcde’ in the Shell.

STEP 6 You can therefore apply .join to the separated name STEP 9 There’s some interesting functions you apply to a
you made in Step 4, combining the letters again to string, such as .capitalize and .title. For example:
form the name:
title=”conan the cimmerian”
name=””.join(name) title.capitalize()
name title.title()
We’ve joined the string back together, and retained the list called
name, passing it through the .join function.

STEP 7 A good example of using the .join function is when STEP 10 You can also use logic operators on strings,
you have a list of words you want to combine into a with the ‘in’ and ‘not in’ functions. These enable
sentence: you to check if a string contains (or does not contain) a sequence
of characters:
list=[“Conan”, “raised”, “his”, “mighty”, “sword”,
“and”, “struck”, “the”, “demon”] message=”Have a nice day”
text=” “.join(list) “nice” in message
text
”bad” not in message
Note the space between the quotes before the .join function (where “day” not in message
there were no quotes in Step 6’s .join). “night” in message

ZZZSFOSXEOLFDWLRQVFRP 71| 71
Working with Data

Formatting Strings
When you work with data, creating lists, dictionaries and objects you may often want
to print out the results. Merging strings with data is easy especially with Python 3, as
earlier versions of Python tended to complicate matters.

STRING FORMATTING
Since Python 3, string formatting has become a much neater process, using the .format function combined with curly brackets.
It’s a more logical and better formed approach than previous versions.

STEP 1 The basic formatting in Python is to call each STEP 3 You can of course also include integers into the mix:
variable into the string using the curly brackets:
number=10000
name=”Conan” print(“{} of {} was a skilled mercenary,
print(“The barbarian hero of the Hyborian Age is: and thief too. He once stole {} gold from a
{}”.format(name)) merchant.”.format(name, place, number))

STEP 2 Remember to close the print function with two sets STEP 4 7KHUHDUHPDQ\GLƪHUHQWZD\VWRDSSO\VWULQJ
of brackets, as you’ve encased the variable in one, formatting, some are quite simple, as we’ve shown
and the print function in another. You can include multiple cases of \RXKHUHRWKHUVFDQEHVLJQLƬFDQWO\PRUHFRPSOH[,WDOOGHSHQGV
string formatting in a single print function: on what you want from your program. A good place to reference
frequently regarding string formatting is the Python Docs webpage,
name=”Conan”
IRXQGDWZZZGRFVS\WKRQRUJOLEUDU\VWULQJKWPO+HUH\RX
place=”Cimmeria”
ZLOOƬQGWRQVRIKHOS
print(“{} hailed from the North, in a cold land
known as {}”.format(name, place))

72 72
| ZZZSFOSXEOLFDWLRQVFRP
Formatting Strings

STEP 5 Interestingly you can reference a list using the string STEP 8 You can also print out the content of a user’s input
formatting function. You need to place an asterisk in in the same fashion:
front of the list name:
name=input(“What’s your name? “)
numbers=1, 3, 45, 567546, 3425346345 print(“Hello {}.”.format(name)
print(“Some numbers: {}, {}, {}, {}, {}”.
format(*numbers))

STEP 6 With indexing in lists, the same applies to calling a STEP 9 You can extend this simple code example to display
list using string formatting. You can index each item WKHƬUVWOHWWHULQDSHUVRQoVHQWHUHGQDPH
according to its position (from 0 to however many are present):
name=input(“What’s your name? “)
numbers=1, 4, 7, 9 print(“Hello {}.”.format(name))
print(“More numbers: {3}, {0}, {2}, lname=list(name)
{1}.”.format(*numbers)) print(“The first letter of your name is a {0}”.
format(*lname))

STEP 7 And as you probably suspect, you can mix strings STEP 10 You can also call upon a pair of lists and reference
and integers in a single list to be called in the them individually within the same print function.
.format function: Looking back the code from Step 7, you can alter it with:
characters=[“Conan”, “Belit”, “Valeria”, 19, 27, names=[“Conan”, “Belit”, “Valeria”]
20] ages=[25, 21, 22]
print (“{0} is {3} years old. Whereas {1} is {4}
Creating two lists. Now you can call each list, and individual items:
years old.”.format(*characters))
print(“{0[0]} is {1[0]} years old. Whereas {0[1]}
is {1[1]} years old.”.format(names, ages))

ZZZSFOSXEOLFDWLRQVFRP 73| 73
Working with Data

Date and Time


:KHQZRUNLQJZLWKGDWDLWoVRIWHQKDQG\WRKDYHDFFHVVWRWKHWLPH)RUH[DPSOH\RX
may want to time-stamp an entry or see at what time a user logged into the system and
for how long. Luckily acquiring the date and time is easy, thanks to the Time module.

TIME LORDS
The Time module contains functions that help you retrieve the current system time, reads the date from strings, formats the
time and date and much more.

STEP 1 First you need to import the Time module. It’s one STEP 3 You can see the structure of how time is presented
WKDWoVEXLOWLQWR3\WKRQVR\RXVKRXOGQoWQHHGWR by entering:
drop into a command prompt and pip install it. Once it’s imported,
time.local.time()
you can call the current time and date with a simple command:
The output is displayed as such: ‘time.struct_time(tm_
import time
year=2017, tm_mon=9, tm_mday=7, tm_hour=9, tm_
time.asctime()
min=6, tm_sec=13, tm_wday=3, tm_yday=250, tm_
isdst=0)’; obviously dependent on your current time as opposed
to the time this book was written.

STEP 2 The time function is split into nine tuples, these are STEP 4 There are numerous functions built into the Time
divided up into indexed items, as with any other module. One of the most common of these is
tuple, and shown in the screen shot below. .strftime(). With it, you’re able to present a wide range of arguments
as it converts the time tuple into a string. For example, to display the
current day of the week you can use:
time.strftime(‘%A’)

74 74
| ZZZSFOSXEOLFDWLRQVFRP
Date and Time

STEP 5 This naturally means you can incorporate various STEP 8 You saw at the end of the previous section, in the
functions into your own code, such as: code to calculate Pi to however many decimal places
the users wanted, you can time a particular event in Python. Take
time.strftime(“%a”)
the code from above and alter it slightly by including:
time.strftime(“%B”)
time.strftime(“%b”) start_time=time.time()
time.strftime(“%H”)
Then there’s:
time.strftime(“%H%M”)
endtime=time.time()-start_time

STEP 6 Note the last two entries, with %H and %H%M, as STEP 9 The output will look similar to the screenshot below.
you can see these are the hours and minutes and as The timer function needs to be either side of the
the last entry indicates, entering them as %H%M doesn’t display the input statement, as that’s when the variable name is being created,
time correctly in the Shell. You can easily rectify this with: depending on how long the user took to log in. The length of time is
then displayed on the last line of the code as the endtime variable.
time.strftime(“%H:%M”)

STEP 7 This means you’re going to be able to display STEP 10 There’s a lot that can be done with the Time
either the current time or the time when module; some of it is quite complex too, such as
something occurred, such as a user entering their name. Try displaying the number of seconds since January 1st 1970. If you
this code in the Editor: want to drill down further into the Time module, then in the Shell
enter: help(time)WRGLVSOD\WKHFXUUHQW3\WKRQYHUVLRQKHOSƬOH
import time
for the Time module.
name=input(“Enter login name: “)
print(“Welcome”, name, “\d”)
print(“User:”, name, “logged in at”, time.
strftime(“%H:%M”))
Try to extend it further to include day, month, year and so on.

ZZZSFOSXEOLFDWLRQVFRP 75| 75
Working with Data

Opening Files
,Q3\WKRQ\RXFDQUHDGWH[WDQGELQDU\ƬOHVLQ\RXUSURJUDPV<RXFDQDOVRZULWHWRƬOH
ZKLFKLVVRPHWKLQJZHZLOOORRNDWQH[W5HDGLQJDQGZULWLQJWRƬOHVHQDEOHV\RXWR
output and store data from your programs.

OPEN, READ AND WRITE


,Q3\WKRQ\RXFUHDWHDƬOHREMHFWVLPLODUWRFUHDWLQJDYDULDEOHRQO\SDVVLQWKHƬOHXVLQJWKHRSHQ IXQFWLRQ)LOHVDUHXVXDOO\
categorised as text or binary.

STEP 1 Start by entering some text into your system’s text STEP 3 If you now enter poem into the Shell, you will get
editor. The text editor is best, not a word processor, VRPHLQIRUPDWLRQUHJDUGLQJWKHWH[WƬOH\RXoYHMXVW
as word processors include background formatting and other asked to be opened. You can now use the poem variable to read the
elements. In our example, we have the poem The Cimmerian, by FRQWHQWVRIWKHƬOH
5REHUW(+RZDUG<RXQHHGWRVDYHWKHƬOHDVSRHPW[W
poem.read()
Note than a /n entry in the text represents a new line, as you
used previously.

STEP 2 <RXXVHWKHRSHQ IXQFWLRQWRSDVVWKHƬOHLQWRD STEP 4 If you enter poem.read() a second time you will
YDULDEOHDVDQREMHFW<RXFDQQDPHWKHƬOHREMHFW QRWLFHWKDWWKHWH[WKDVEHHQUHPRYHGIURPWKHƬOH
anything you like, but you will need to tell Python the name and You will need to enter: poem=open(“/home/pi/Documents/
ORFDWLRQRIWKHWH[WƬOH\RXoUHRSHQLQJ Poem.txt”)DJDLQWRUHFUHDWHWKHƬOH7KLVWLPHKRZHYHUHQWHU
poem=open(“/home/pi/Documents/Poem.txt”) print(poem.read())
This time, the /n entries are removed in favour of new lines and
readable text.

76 76
| ZZZSFOSXEOLFDWLRQVFRP
Opening Files

STEP 5 Just as with lists, tuples, dictionaries and so on, STEP 8 Extending this further, you can use readlines() to
you’re able to index individual characters of the grab all the lines of the text and store them as
text. For example: multiple lists. These can then be stored as a variable:
poem.read(5) poem=open(“/home/pi/Documents/Poem.txt”)
lines=poem.readlines()
'LVSOD\VWKHƬUVWƬYHFKDUDFWHUVZKLOVWDJDLQHQWHULQJ
lines[0]
poem.read(5) lines[1]
lines[2]
:LOOGLVSOD\WKHQH[WƬYH(QWHULQJ  ZLOOGLVSOD\RQHFKDUDFWHUDW
a time.

STEP 6 Similarly, you can display one line of text at a time by STEP 9 You can also use the for statement to read the lines
using the readline() function. For example: of text back to us:
poem=open(“/home/pi/Documents/Poem.txt”) for lines in lines:
poem.readline() print(lines)
:LOOGLVSOD\WKHƬUVWOLQHRIWKHWH[WZLWK Since this is Python, there are other ways to produce the same output:
poem.readline() poem=open(“/home/pi/Documents/Poem.txt”)
for lines in poem:
Displaying the next line of text once more.
print(lines)

STEP 7 You may have guessed that you can pass the STEP 10 Let’s imagine that you want to print the text one
readline() function into a variable, thus allowing you character at a time, like an old dot matrix printer
to call it again when needed: would. You can use the Time module mixed with what you’ve looked
at here. Try this:
poem=open(“/home/pi/Documents/Poem.txt”)
line=poem.readline() import time
line poem=open(“/home/pi/Documents/Poem.txt”)
lines=poem.read()
for lines in lines:
print(lines, end=””)
time.sleep(.15)
The output is fun to view, and easily incorporated into your own code.

ZZZSFOSXEOLFDWLRQVFRP 77| 77
Working with Data

Writing to Files
7KHDELOLW\WRUHDGH[WHUQDOƬOHVZLWKLQ3\WKRQLVFHUWDLQO\KDQG\EXWZULWLQJWRDƬOHLV
better still. Using the write() function, you’re able to output the results of a program to
DƬOHWKDW\RXFDQWKHQUHDG EDFNLQWR3\WKRQ

WRITE AND CLOSE


7KHZULWH IXQFWLRQLVVOLJKWO\PRUHFRPSOH[WKDQUHDG $ORQJZLWKWKHƬOHQDPH\RXPXVWDOVRLQFOXGHDQDFFHVVPRGHZKLFK
GHWHUPLQHVZKHWKHUWKHƬOHLQTXHVWLRQLVLQUHDGRUZULWHPRGH

STEP 1 Start by opening IDLE and enter the following: STEP 3 +RZHYHUWKHDFWXDOWH[WƬOHLVVWLOOEODQN \RXFDQ
check by opening it up). This is because you’ve
t=open(“/home/pi/Documents/text.
ZULWWHQWKHOLQHRIWH[WWRWKHƬOHREMHFWEXWQRWFRPPLWWHGLWWRWKH
txt”,”w”)
ƬOHLWVHOI3DUWRIWKHZULWH IXQFWLRQLVWKDW\RXQHHGWRFRPPLWWKH
Change the destination from /home/pi/Documents to your own FKDQJHVWRWKHƬOH\RXFDQGRWKLVE\HQWHULQJ
V\VWHP7KLVFRGHZLOOFUHDWHDWH[WƬOHFDOOHGWH[WW[WLQZULWHPRGH
t.close()
XVLQJWKHYDULDEOHnWo,IWKHUHoVQRƬOHRIWKDWQDPHLQWKHORFDWLRQLW
will create one. If one already exits, it will overwrite it, so be careful.

STEP 2 <RXFDQQRZZULWHWRWKHWH[WƬOHXVLQJWKHZULWH  STEP 4 ,I\RXQRZRSHQWKHWH[WƬOHZLWKDWH[WHGLWRU


function. This works opposite to read(), writing lines you can see that the line you created has been
instead of reading them. Try this: ZULWWHQWRWKHƬOH7KLVJLYHVXVWKHIRXQGDWLRQIRUVRPHLQWHUHVWLQJ
SRVVLELOLWLHVSHUKDSVWKHFUHDWLRQRI\RXURZQORJƬOHRUHYHQWKH
t.write(“You awake in a small, square room. A
beginning of an adventure game.
single table stands to one side, there is a locked
door in front of you.”)
Note the 109. It’s the number of characters you’ve entered.

78 78
| ZZZSFOSXEOLFDWLRQVFRP
Writing to Files

STEP 5 7RH[SDQGWKLVFRGH\RXFDQUHRSHQWKHƬOHXVLQJ STEP 8 <RXFDQSDVVYDULDEOHVWRDƬOHWKDW\RXoYHFUHDWHG


‘a’, for access or append mode. This will add any text in Python. Perhaps you want the value of Pi to be
DWWKHHQGRIWKHRULJLQDOOLQHLQVWHDGRIZLSLQJWKHƬOHDQGFUHDWLQJ ZULWWHQWRDƬOH<RXFDQFDOO3LIURPWKH0DWKPRGXOHFUHDWHDQHZ
a new one. For example: ƬOHDQGSDVVWKHRXWSXWRI3LLQWRWKHQHZƬOH
t=open(“/home/pi/Documents/text.txt”,”a”) import math
t.write(“\n”) print(“Value of Pi is: “,math.pi)
t.write(“ You stand and survey your surroundings. print(“\nWriting to a file now…”)
On top of the table is some meat, and a cup of
water.\n”)

STEP 6 You can keep extending the text line by line, STEP 9 Now let’s create a variable called pi and assign it the
ending each with a new line (\n). When you’re value of Pi:
GRQHƬQLVKWKHFRGHZLWKWFORVH DQGRSHQWKHƬOHLQDWH[W
pi=math.pi
editor to see the results:
<RXDOVRQHHGWRFUHDWHDQHZƬOHLQZKLFKWRZULWH3LWR
t.write(“The door is made of solid oak with iron
strips. It’s bolted from the outside, locking you t=open(“/home/pi/Documents/pi.txt”,”w”)
in. You are a prisoner!.\n”)
5HPHPEHUWRFKDQJH\RXUƬOHORFDWLRQWR\RXURZQSDUWLFXODU
t.close()
system setup.

STEP 7 7KHUHDUHYDULRXVW\SHVRIƬOHDFFHVVWRFRQVLGHU STEP 10 7RƬQLVK\RXFDQXVHVWULQJIRUPDWWLQJWRFDOOWKH


using the open() function. Each depends on how the YDULDEOHDQGZULWHLWWRWKHƬOHWKHQFRPPLWWKH
ƬOHLVDFFHVVHGDQGHYHQWKHSRVLWLRQRIWKHFXUVRU)RUH[DPSOHU FKDQJHVDQGFORVHWKHƬOH
RSHQVDƬOHLQUHDGDQGZULWHDQGSODFHVWKHFXUVRUDWWKHVWDUWRI
t.write(“Value of Pi is: {}”.format(pi))
WKHƬOH
t.close()
You can see from the results that you’re able to pass any variable to
DƬOH

ZZZSFOSXEOLFDWLRQVFRP 79| 79
Working with Data

Exceptions
When coding, you’ll naturally come across some issues that are out of your control.
Let’s assume you ask a user to divide two numbers and they try to divide by zero. This
will create an error and break your code.

EXCEPTIONAL OBJECTS
5DWKHUWKDQVWRSWKHƮRZRI\RXUFRGH3\WKRQLQFOXGHVH[FHSWLRQREMHFWVZKLFKKDQGOHXQH[SHFWHGHUURUVLQWKHFRGH<RX
can combat errors by creating conditions where exceptions may occur.

STEP 1 You can create an exception error by simply trying STEP 3 You can use the functions raise exception to create
to divide a number by zero. This will report back our own error handling code within Python. Let’s
with the ZeroDivisionError: Division by zero message, as seen in the assume your code has you warping around the cosmos, too much
screenshot. The ZeroDivisionError part is the exception class, of however results in a warp core breach. To stop the game from
which there are many. exiting due to the warp core going supernova, you can create a
custom exception:
raise Exception(“warp core breach”)

STEP 2 Most exceptions STEP 4 To trap any errors in the code you can encase the
are raised potential error within a try: block. This block consists
automatically when Python of try, except, else, where the code is held within try:, then if there’s
comes across something that’s an exception do something, else do something else.
inherently wrong with the code.
However, you can create your
own exceptions that are designed
to contain the potential error and
react to it, as opposed to letting
the code fail.

80 80
|
([FHSWLRQV

STEP 5 For example, use the divide by zero error. You can STEP 8 1DWXUDOO\\RXFDQTXLFNO\Ƭ[WKHLVVXHE\FKDQJLQJ
create an exception where the code can handle the the “r” read only instance with a “w” for write. This,
error without Python quitting due to the problem: DV\RXDOUHDG\NQRZZLOOFUHDWHWKHƬOHDQGZULWHWKHFRQWHQWWKHQ
FRPPLWWKHFKDQJHVWRWKHƬOH7KHHQGUHVXOWZLOOUHSRUWDGLƪHUHQW
try:
set of circumstances, in this case, a successful execution of the code.
a=int(input(“Enter the first number: “))
b=int(input(“Enter the second number: “))
print(a/b)
except ZeroDivisionError:
print(“You have tried to divide by zero!”)
else:
print(“You didn’t divide by zero. Well done!”)

STEP 6 You can use exceptions to handle a variety of useful STEP 9 <RXFDQDOVRXVHDƬQDOO\EORFNZKLFKZRUNVLQD
tasks. Using an example from our previous tutorials, similar fashion but you can’t use else with it. To use
OHWoVDVVXPH\RXZDQWWRRSHQDƬOHDQGZULWHWRLW our example from Step 6:
try: try:
txt = open(“/home/pi/Documents/textfile.txt”, txt = open(“/home/pi/Documents/textfile.txt”,
“r”) “r”)
txt.write(“This is a test. Normal service will try:
shortly resume!”) txt.write(“This is a test. Normal service will
except IOError: shortly resume!”)
print (“Error: unable to write the file. Check finally:
permissions”) print (“Content written to file successfully.
else: Have a nice day.”)
print (“Content written to file successfully. txt.close()
Have a nice day.”) except IOError:
txt.close() print (“Error: unable to write the file. Check
permissions”)

STEP 7 2EYLRXVO\WKLVZRQoWZRUNGXHWRWKHƬOHWH[WƬOH STEP 10 As before an error will occur as you’ve used the
txt being opened as read only (the “r” part). So in “r” read-only permission. If you change it to a “w”,
this case rather than Python telling you that you’re doing something then the code will execute without the error being displayed in the
wrong, you’ve created an exception using the IOError class IDLE Shell. Needless to say, it can be a tricky getting the exception
informing the user that the permissions are incorrect. FRGHULJKWWKHƬUVWWLPH3UDFWLVHWKRXJKDQG\RXZLOOJHWWKHKDQJ
of it.

ZZZSFOSXEOLFDWLRQVFRP 81| 81
Working with Data

Python Graphics
:KLOHGHDOLQJZLWKWH[WRQWKHVFUHHQHLWKHUDVDJDPHRULQDSURJUDPLVJUHDWWKHUH
will come a time when a bit of graphical representation wouldn’t go amiss. Python 3
has numerous ways in which to include graphics and they’re surprisingly powerful too.

GOING GRAPHICAL
You can draw simple graphics, lines, squares and so on, or you can use one of the many Python modules available, to bring out
VRPHVSHFWDFXODUHƪHFWV

STEP 1 One of the best graphical modules to begin learning STEP 3 The command turtle.circle(50) is what draws the
Python graphics is Turtle. The Turtle module is, as circle on the screen, with 50 being the size. You
the name suggests, based on the turtle robots used in many schools, can play around with the sizes if you like, going up to 100, 150 and
that can be programmed to draw something on a large piece beyond; you can draw an arc by entering: turtle.circle(50,
RISDSHURQWKHƮRRU7KH7XUWOHPRGXOHFDQEHLPSRUWHGZLWK 180), where the size is 50, but you’re telling Python to only draw
import turtle. 180° of the circle.

STEP 2 Let’s begin by drawing a simple circle. Start a New STEP 4 The last part of the circle code tells Python to keep
File, then enter the following code: the window where the drawing is taking place to
remain open, so the user can click to close it. Now, let’s make a square:
import turtle
import turtle
turtle.circle(50)
turtle.getscreen()._root.mainloop() print(“Drawing a square…”)
As usual press F5 to save the code and execute it. A new window will for t in range(4):
now open up and the ‘Turtle’ will draw a circle. turtle.forward(100)
turtle.left(90)
turtle.getscreen()._root.mainloop()
You can see that we’ve inserted a loop to draw the sides of the square.

82 82
| ZZZSFOSXEOLFDWLRQVFRP
Python Graphics

STEP 5 You can add a new line to the square code to add STEP 8 Now let’s get the code by importing the Pygame module:
some colour:
import pygame
turtle.color(“Red”) pygame.init()
Then you can even change the character to an actual turtle by entering: img = pygame.image.load(“RPi.png”)
turtle.shape(“turtle”) white = (255, 255, 255)
w = 900
You can also use the command turtle.begin_fill(), and
h = 450
turtle.end_fill()WRƬOOLQWKHVTXDUHZLWKWKHFKRVHQFRORXUV
screen = pygame.display.
UHGRXWOLQH\HOORZƬOOLQWKLVFDVH
set_mode((w, h))
screen.fill((white))
screen.fill((white))
screen.blit(img,(0,0))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()

STEP 6 You can see that the Turtle module can draw STEP 9 In the previous step you imported pygame, initiated
out some pretty good shapes and become a little the pygame engine and asked it to import our saved
more complex as you begin to master the way it works. Enter 5DVSEHUU\3LORJRLPDJHVDYHGDV53LSQJ1H[W\RXGHƬQHGWKH
this example: background colour of the window to display the image and the
window size as per the actual image dimensions. Finally you have a
from turtle import *
loop to close the window.
color(‘red’, ‘yellow’)
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
,WoVDGLƪHUHQWPHWKRG
EXWYHU\HƪHFWLYH

STEP 7 Another way in which you can display graphics is STEP 10 Press F5 to save and execute the code and your
by using the Pygame module. There are numerous image will be displayed in a new window. Have a
ways in which pygame can help you output graphics to the screen play around with the colours, sizes and so on and take time to look
EXWIRUQRZOHWoVORRNDWGLVSOD\LQJDSUHGHƬQHGLPDJH6WDUWE\ up the many functions within the Pygame module too.
RSHQLQJDEURZVHUDQGƬQGLQJDQLPDJHWKHQVDYHLWWRWKHIROGHU
where you save your Python code.

ZZZSFOSXEOLFDWLRQVFRP 83| 83
Working with Data

Combining What
You Know So Far
Based on what you’ve looked at over this section, let’s combine it all and come up with
a piece of code that can easily be applied into a real-world situation; or at the very
least, something which you can incorporate into your programs.

LOGGING IN
For this example, let’s look to a piece of code that creates user logins and then allows them to log into the system and write
the time they logged in at. You can even include an option to quit the program by pressing ‘q’.

STEP 1 Begin by importing the Time module, creating STEP 3 The global status statement separates a local
a new dictionary to handle the usernames and variable from one that can be called throughout
passwords and creating a variable to evaluate the current status of the code, this way you can use the q=quit element without it being
the program: changed inside the function. We’ve also referenced some newly
GHƬQHGIXQFWLRQVROG8VHUDQGQHZ8VHUZKLFKZHoOOJHWWRQH[W
import time
users = {}
status = “”

STEP 4 The newUser function is next:


def newUser():
STEP 2 1H[W\RXQHHGWRGHƬQHVRPHIXQFWLRQV<RXFDQ createLogin = input(“Create a login name: “)
begin by creating the main menu, where all users
if createLogin in users:
will return to after selecting the available options:
print (“\nLogin name already exists!\n”)
def mainMenu(): else:
global status createPassw = input(“Create password: “)
status = input(“Do you have a login account? users[createLogin] = createPassw
y/n? Or press q to quit.”) print(“\nUser created!\n”)
if status == “y”: logins=open(“/home/pi/Documents/logins.txt”,
oldUser() “a”)
elif status == “n”: logins.write(“\n” + createLogin + “ “ +
newUser() createPassw)
elif status == “q”: logins.close()
quit()
This creates a new user and password, and writes the entries into a
ƬOHFDOOHGORJLQVW[W

84 84
| ZZZSFOSXEOLFDWLRQVFRP
&RPELQLQJ:KDW<RX.QRZ6R)DU

STEP 5 You will need to specify your own location for the STEP 8 Finally, you need to continually check that the ‘q’ key
ORJLQVW[WƬOHVLQFHZHoUHXVLQJD5DVSEHUU\3L hasn’t been pressed to exit the program. We can do
Essentially, this adds the username and password inputs from the this with:
user to the existing users{} dictionary, so the key and value structure
while status != “q”:
remains: each user is the key, the password is the value.
status = displayMenu()

STEP 6 Now to create the oldUser function:

def oldUser():
login = input(“Enter login name: “)
passw = input(“Enter password: “)
# check if user exists and login matches
password
if login in users and users[login] == passw:
print (“\nLogin successful!\n”)
print (“User:”, login, “accessed the system
on:”, time.asctime())
else:
print (“\nUser doesn’t exist or wrong
password!\n”)
STEP 9 Although a seemingly minor two lines, the while
loop is what keeps the program running. At the end
of every function it’s checked against the current value of status. If
that global value isn’t ‘q’ then the program continues. If it’s equal to
‘q’ then the program can quit.

STEP 10 You can now create users, then log in with their
QDPHVDQGSDVVZRUGVZLWKWKHORJLQVW[WƬOH
being created to store the login data and successful logins being
time-stamped. Now it’s up to you to further improve the code.
Perhaps you can import the list of created users from a previous
session and display a graphic upon a successful login?

STEP 7 There’s a fair bit happening here. There are login


and passw variables, which are then matched to the
users dictionary. If there’s a match, then you have a successful login
and the time and date of the login is outputted. If they don’t match,
then you print an error and the process starts again.

ZZZSFOSXEOLFDWLRQVFRP 85| 85
Working with Data

Python in Focus:
Gaming
Although not always considered as the ideal programming language for developing
games, Python has come a long way in recent years and is now one of the contributing
elements to a huge number of titles.
The video game industry generates something in the region of $140 billion each year, and that number is growing fast. It’s a long way from
the 8-bit days of the Commodore 64 and ZX Spectrum; the arcade titles that used to devour our pocket money and the wood panelled
KRPHFRQVROHVWKDW$WDULORYLQJO\GHYHORSHG7KHVHGD\VLWoVDOODERXWWHDPVRIFRGHUVJUDSKLFDUWLVWVPXVLFLDQV35SURMHFWVDQG
development platforms.

GAME CODE
Coding a game from scratch, using raw code, has become
something of the past. Most games these days are created using
DUDQJHRIGHYHORSPHQWWRROV7KHVHWRROVFDQEHRƪWKHVKHOI
engines, such as the Unreal Engine, while others are custom built
around an original product, such as the world generating engine
that Bethesda use for the Skyrim and Fallout series of games.
2WKHUVH[DPSOHVFDQEHFRGHGIURPWKHJURXQGXSEXWWKHVH
DUHJHQHUDOO\IHZDQGIDUEHWZHHQ6RZKHUHGRHV3\WKRQƬW
into all this?

The limiting factor with Python is performance. While most


games require a huge degree of performance from the platform BUILDING TOOLS
for which they are written, Python’s code, which is good, isn’t
really designed to cope with the fast-paced formula on which In the game industry, Python is mostly limited to the
JDPHVVXFKDV%DWWOHƬHOGRUWKH&DOORI'XW\VHULHVDUHEDVHG development of in-game tools used by the developers of the
These games are often coded with C++, or some other form of JDPHRUWRKHOSEULGJHWKHJDSVEHWZHHQGLƪHUHQWDUHDVRI
low-level programming language. But that doesn’t mean Python FRGH)RUH[DPSOHLQJDPHWRROVFRGHGLQ3\WKRQFDQEHXVHGE\
is left out in the cold when it comes to game development, in GHVLJQHUVWRFUHDWHOHYHOVIRUWKHJDPHRUVSHFLƬFHOHPHQWVWKDW
fact it’s quite the opposite. would make up a character’s inventory, or even creating dialog
between the player and non-playing characters in the game.

<RXZLOODOVRƬQGWKDW3\WKRQFDQEHXVHGWRFRQWUROWKHJDPHoV
$, $UWLƬFLDO,QWHOOLJHQFH ZKLFKZLOOJLYHWKHFKDUDFWHUVLQDJDPH
DFHUWDLQHOHPHQWRIOLIH$VDQH[DPSOHWKHSRSXODU6LPVJDPHV
consist of characters other than the one the gamer controls.
These Sims will go about their business with their actions
determined by the player’s choices, this involves an advanced
IRUPRI$UWLƬFLDO,QWHOOLJHQFHWKDWLVFRGHGXVLQJ3\WKRQ

2WKHUH[DPSOHVLQFOXGHPDQ\RIWKHDYDLODEOHRSHQZRUOG
games, where the introduction of the player will change the
course of a village’s, Town’s, or even city’s inhabitant’s behaviour.
%ORZXSDIHZFDUVLQWKHPLGGOHRIWKHVWUHHWDQGLWoOODƪHFW
the way the other drivers behave; jump up and down on top of
a market stall in the middle of a medieval village and the folk
around you will react. This, again, is all down to Python code
written within the main code of the game, alongside the game
development engine.

86 86
| ZZZSFOSXEOLFDWLRQVFRP
Python in Focus: Gaming

3<7+21Ǖ32:(5('*$0(6
6RPHJRRGH[DPSOHVRIWKHW\SHVRIJDPHVLQZKLFK3\WKRQLV
used are the following:

%DWWOHƬHOG – Python is used for the game’s add-ons and


functionality of the player elements.
7KH6LPV – AI, and many of the game’s interactions.
&LYLOLVDWLRQ – Python is used throughout the Civ games,
controlling movement and the non-player AI.
(YH2QOLQHs8WLOLVHV3\WKRQIRUƮRDWLQJSRLQWQXPEHU
calculations and other tasks.
:RUOGRI7DQNV – Python is used to control AI objects and detail
the large amount of graphical data.

In particular, it’s worth noting that Python’s use in games is due


to its ability to automate repetitive tasks quickly. While another
programming language may be faster at drawing the graphics
on the screen, Python can quickly repeat resizing hundreds of
WH[WXUHVLQEDWFKHV7KHUHoVDOVR3\WKRQoVH[FHOOHQWDQGVL]HDEOH
OLEUDULHVWKDWFDQEHWZHDNHGIRUFHUWDLQWDVNVVSHFLƬFDOO\
in-game tasks freeing up other components to deliver the
performance that modern games need.

KEEP ON
GAMING
,QVKRUWZKLOH3\WKRQPD\
QRWEHWKHLGHDOODQJXDJH
ZLWKZKLFKWRFUHDWHD
PRGHUQJDPHHQWLUHO\LWV
XVHLVRIWHQEHKLQGWKH
VFHQHVLQDUHDVZKHUHRWKHU
SURJUDPPLQJODQJXDJHV
ZLOOVWUXJJOH3\WKRQFDQ
EHXVHGDVWKHJOXHWKDW
VWLFNVHOHPHQWVRIJDPH
WHFKQRORJLHVWRJHWKHU
FUHDWLQJFRPSOH[$,RUVLPSO\
GHVLJQLQJDGLDORJER[

ZZZSFOSXEOLFDWLRQVFRP 87| 87
REVIEWS

Tech Round-Up
If you’re looking for something
different for your device, this is
the place to start. Each issue,
we take a look at some of the
best and worst peripherals,
gadgets and apps that have
crossed our path.

88 www.pclpublications.com
REVIEWS

Hardware Reviews
90 STM ChargeTree Swing Charging Station
92 Joby GripTight GorillaPod for MagSafe
93 Devolo Magic 2 WiFi 6 Whole Home Wi-Fi Kit
94 SanDisk iXpand Flash Drive Luxe 256GB
94 Kensington StudioDock Charging Stand
95 MINIX NEO P1 3-Port GaN Charger
96 Twelve South PowerPic Charging Stand
97 FRITZ!Repeater 6000 WiFi Extender
98 Airpulse P100X Stereo Speaker

Software Reviews
100 Procreate Pocket
102 Splice – Video Editor & Maker
103 Zombies, Run!
104 Radio Garden
105 iMazing 2
106 Impressive iOS Photography Apps

Games Reviews
108 Alien: Isolation
110 Double DragonTrilogy
111 Another World – 20th
112 Grand Theft Auto Liberty City Stories
114 Tengai
115 BADLAND, Game of the Year Edition

www.pclpublications.com 89
STM ChargeTree Swing
Charging Station
Charge your new smartphone, Apple Watch and Airpods Pro all at once.

Info//
STM Ltd.
www.stmgoods.com
£69.95, $79.95, TBA €

T
his second-generation STM ChargeTree makes
a few minor, but welcome, changes from the
original model. Like the original ChargeTree
it’s available in black or white, and it once more
charges a Qi-compatible smartphone, AirPods (with
a wireless charging case), and an Apple Watch - all
at the same time, using only one power socket. You
just need a USB-C mains adapter of at least 20W. It’s
not supplied, but they’re not hard to come by.
As before, you charge your phone by resting it
on the backward-leaning mat at the front of the
ChargeTree Swing. It’s comfortably cushioned, and
there’s an optional rubber raiser to fit over the foot
if you have a smaller smartphone that needs the
extra height. Also as before, your earbuds sit on a

90 www.pclpublications.com
watch face. Like the original ChargeTree, this one
can charge an Apple Watch Series 2 or later; the first-
generation device not being Qi-compatible.
But our favourite change is the way the lights
that indicate your tech is charging work. As before,
charging pad mounted horizontally on the stand. there are three LEDs in the foot of the ChargeTree
As it’s designed with Apple fans in mind, this is Swing, one for each device. When you place your
intended for wireless-charging AirPods, though phone, Apple Watch and/or your earbuds on its
there’s no reason a third-party set of earbuds charger, a corresponding LED lights up to let you
shouldn’t charge there, as long as they have a know it’s correctly seated and charging. But now
wireless-charging case. Mine, for instance, do. these lights go off after a few seconds. At last, you
can use a ChargeTree in your bedroom without
being kept awake by always-on illuminations.
Leading the charge... The original ChargeTree was good, but
The main change from the previous ChargeTree
the sleep-destroying LEDs and inability to see
is the way it handles the Apple Watch. This is
the watch face from your pillow were serious
now charged on an extending arm, which can be
oversights. The new STM ChargeTree Swing corrects
retracted when not in use. It looks much smarter
both these faults, and lets you use it however you
there, and if you want to know the time, you can just
want, including on the bedside table.
nudge your desk or bedside table to illuminate the

www.pclpublications.com 91
Joby GripTight
GorillaPod for MagSafe
New intro ‘Make the most of your smartphone's great camera.

Info//
Vitec Imaging Solutions Spa
https://joby.com
£62.95, $69.95, 69,95 €

T
he GorillaPod range of camera and mobile part of the GripTight through 360 degrees, changing
phone tripods is among the most versatile the orientation of the phone without removing it,
and comprehensive mounts around, and now and if you want to use a non-MagSafe device – or
there’s one for the latest, MagSafe smartphones. simply to hold your smartphone tighter – just twist
The lower half of the device is business as usual; around the jaws at either end of an arm extending
a regular GorillaPod tripod which you can bend from the magnet and pop it in using the spring
and mould into almost any shape. Need a shorter grips. The GripTight unit screws securely into the
leg to compensate for an uneven platform? You’ve tripod, and two screw-holes either side of it can
got it. Want to mount your phone at a lower height house optional add-ons such as a light or a mic (not
without sacrificing stability? Not a problem. You can supplied).
even hold the legs together and use it as a (short) Joby GripTight GorillaPod for MagSafe is the ideal
selfie stick, or bend them around a tree branch or photography companion for MagSafe phones. It’s
metal pole to hold your phone in positions that just strong, stable, versatile and extremely useful.
wouldn’t be possible with a traditional tripod.

Click and stick


The upper part of the device, which holds the
smartphone when using its camera, has a large
circular magnet that’s designed to connect to
MagSafe iPhones. Just place your phone on the
silicon pad that tops the magnet and it snaps into
place, firmly and securely. You can rotate the magnet

92 www.pclpublications.com
Devolo Magic 2
WiFi 6 Whole Home Wi-Fi Kit
Use your new smartphone's Wi-Fi all over the house.

Info//
devolo AG
www.devolo.co.uk
£349.99, $299.99, 499,90

W
e've long been fans of devolo’s excellent attic is too far from your Wi-Fi, and heavy stone walls
homeplug devices. Plug one into the and thick ceilings no longer block your coverage.
mains near your router and connect it Just put a homeplug on the opposite side of the
with a supplied Ethernet cable, then set up the obstacle to your router, and your data is transferred
other bundled homeplugs anywhere in the house, using your household electrical wiring. It works
and they use your home’s electrical cabling to carry brilliantly, and the extra stability offered by Wi-Fi 6
your network data. Individual plugs offer Wi-Fi means you no longer get an interrupted service if the
hotspots and/or Ethernet ports, so you can make whole family is online at the same time.
cabled and wireless connections to the homeplug Several devolo Magic 2 Wi-Fi 6 packs are
instead of directly to your router. At last, you can available. The one reviewed here is the top-of-
have Wi-Fi throughout the house, even a long way the-range Whole Home Wi-Fi Kit, which offers a
from the router, and cabled Internet access without homeplug for your router and two for the house,
having to drill holes in the walls and trail cables both of which give you Wi-Fi 6 hotspots and twin
under the carpets. Ethernet ports. A starter kit, with only one Wi-Fi/
These latest devolo homeplugs conform to Ethernet plug supplied is also available, and you
the newx Wi-Fi 6 protocols, which give up to 50% can also buy single plugs to add to your homeplug
faster wireless connectivity than before. At up to network later. All the plugs have through-sockets, so
2400 Mbps, these are the world’s fastest homeplug you can plug an electrical device into the homeplug,
adapters. Wi-Fi 6 is also more stable, and can handle which then plugs into the mains.
more simultaneously connected devices too. All Homeplugs are not the cheapest solution to Wi-Fi
the features of the older devolo Magic homeplugs, problems, but they’re certainly one of the easiest to
such as beam forming and access point steering, are use and most effective. As devolo homeplugs are the
included in the new devices. best there is, they’re definitely recommended.

Plug and play


Devolo Magic 2 WiFi 6 is easy to set up using the free
devolo Home Network App. There’s nothing to fear
here at all. Within a few minutes, you have wireless
Internet in places your home router can’t reach, and
access to cabled networking in rooms where you’ve
set up a plug. You no longer need to worry that the

www.pclpublications.com 93
SanDisk iXpand
Flash Drive Luxe 256GB
Transfer your files and back up your photos in a flash.

Info//
Y
ou can use this double-ended flash drive to
transfer files between devices, and back up
SanDisk
your photos and videos from your tablet or
www.westerndigital.com
smartphone. Available in 64GB, 128GB or 256GB
£88, $89.99, 82,75 €
capacities, it has a USB-C 3.1 plug on one end, and a
Lightning connector at the other. You can only copy
media and contacts from a smarttphone or tablet,
using the iXpand app, but plug it into a desktop and
you can copy any file.
Transferring files to the flash drive is super
speedy; it’s certainly faster than its predecessor, the
iXpand Flash Drive Go. The iXpand app is easy to use
too. It’s a great way of getting more from your mobile
device’s internal storage, without clogging it up with
things that could be stored elsewhere.

You can automatically back up your photos to the flash drive.

Kensington StudioDock
Charging Stand
The last word in tablet docks?

Info//
T
his handy, mains-powered device is more than just a
Kensington Computer tablet stand. Sure, it can hold your iPad Pro (2018 or
Products Group later, either size), or iPad Air (2020), in Landscape or
www.kensington.com portrait mode, so you can watch media, draw with your Apple
From £321.90, $373.47, Pencil or type comfortably by connecting a keyboard and
€305,64 € mouse. But it’s also a wireless charger for your smarttphone
and/or ear pods. Just place them on the pad at the foot of the
stand. You can also buy an optional Apple Watch charger that
fits on the side of the device.
The stand connects to your iPad’s USB-C socket, and you
can plug in peripherals using the ports at the back. There’s
three USB 3 ports, a HDMI port and an Ethernet port. There’s
an SD Card reader and headphone socket on the side of the
stand too. With these, you can add hard drives, a monitor,
Use your tablet in portrait or landscape mode, and
input devices and more. It’s ideal if you want to turn your iPad
add a second screen.
into a home-and-away computer to use for work and play.

94 www.pclpublications.com
MINIX NEO P1
3-Port GaN Charger
Smaller, more portable but still with plenty of power to offer.

E Info//
arlier in the year we saw the release of the NEO The NEO P1 is constructed from fire-resistant
P2 4-Port GaN Charger. This is a remarkable polycarbonate, with high-density heatsinks and a
and extremely useful multi-port charger that’s low operating temperature. Both sides display the MINIX Technology Limited
bristling with features and comes in at a fantastic MINIX logo and on the front you’ll find the three ports www.minix.com.hk
price. However, MINX has since upped its game and an LED power indicator. On the opposite side of £34.90, $46.18, 39,06 €
yet again and released the P2’s smaller but just as the ports is the dual-prong US plug type, where you
capable brother, the NEO P1. attach whatever plug you need depending on the
The MINIX NEO P1 is a three-port charging station, country you’re charging your devices in.
with a pair of USB-C Power Delivery 3.0 ports offering There’s auto-sensing power distribution
65W, 5~15V/3A, 20V/3.25A and a single USB-A1 36W technology on-board, which protects the devices
Quick Charge 3.0 port at 5V/3A, 9V/3A, 12V/3A and from over-voltage, input and output over-current,
20V/1.8A. While it may lack an extra port over its short circuit and overheating. The auto-sensing
sibling, it certainly makes up for that in portability. plugs also adapts to the international voltages of
The NEO P2 wasn’t a huge charging station by any the plug socket you’re charging from and each port
stretch of the imagination but the P1 is significantly automatically adjusts the power output depending
smaller. Measuring just 50 x 50 x 25mm and weighing on the device that’s being charged from it, as well
a minute 114g, this palm-sized charger does an as activating any quick charge technologies that are
extraordinary job. compatible with the device.
In the box you’ll get the NEO P1 itself, together The NEO P1 is a fantastic addition to the MINIX
with three different types of detachable plugs: Type stable. This tiny, capable and feature-packed charger
I (AU), Type C (EU), and Type G (UK). Without any is the ideal present for those who need to charge on
plugs attached, the P1 features a pull-out Type A (US) the go, while still protecting their devices from the
two-pronged plug. To add a different plug type, you whims of hotel, college, school, university and work
simply slide one of the accompanying plugs over the based plug sockets around the world. Great value
US type prongs when they’re in the retracted position. for money and a must have addition for those who
There’s also a small felt drawstring bag to put travel for work.
the P1 inside when transporting it – incidentally, we
had two bags in our review sample, whether that’s
one for the P1 and another for the plugs or simply a
packaging mistake we’re not sure but we appreciate
the extra bag to contain everything.

www.pclpublications.com 95
Twelve South PowerPic
Charging Stand
The most attractive way to charge your new smartphone yet?

Info//
Twelve South
www.twelvesouth.com
£79.99, $59.99, 64,99 €

W
hat a delightfully clever idea. At a glance, really comes into its own. Aesthetically, it just works.
PowerPic looks like an attractive but Without the iPhone in place, it looks like a stylish,
unremarkable photo frame, but it’s also a attractive photo frame, not a piece of technology
powerful wireless charger that’s perfect for your Qi- trying to be something else. It’s the perfect addition
compatible smartphone or ear pods. to anyone’s side board, fire grate or bedside table.
PowerPic is a solid, clear photo holder, with a
black or white charging unit on the back. It houses
a six-inch by four-inch photograph in landscape or
portrait mode; which is held in place by a plastic
cover, held on by a magnet in each corner. The
whole thing slots into a black or white base. It looks
excellent with a decent photo in place; right at home
in any room. You connect it to the mains using a
USB-C cable (supplied) and a 20w USB-C power
adapter (not supplied).

On a charge
Of course, the PowerPic really comes into its own
when you need to charge your iPhone or AirPods.
You simply place your wireless charging-compatible
device on the stand, leaning against the upright
photo-holding section, and it charges; with no cables
to plug in. It can even charge through a case of up to
3mm thick. This new PowerPic model is definitely a
big step up from its predecessor, which had a bulky
frame around the photo mount, was portrait-mode
only and couldn’t charge ear pods.
PowerPic looks great anywhere in the house.
If you don’t have a photo handy, there’s a two-
sided design in the box that resembles the phone’s
wallpapers, but it’s when you clip in a picture that it

96 www.pclpublications.com
FRITZ!Repeater 6000
WiFi Extender
Extend your Wi-Fi network for your new smartphone or smart watch.

Info//
AVM GmbH
https://en.avm.de
£219.00, 219,00 € (Not sold in
the USA)

A
wireless extender is designed to compliment older model.
your wireless router by extending the reach One thing that hasn’t changed is that the
of your Wi-Fi network. Set it up in a location FRITZ!Repeater 6000 supports Mesh Wi-Fi. This
that’s within the range of your current network, means instead of appearing as a separate access
and it provides an access point of its own, which point, it meshes with your router’s own signal to form
in turn transfers data to and from your router. The a single network. In practical terms, it means that
FRITZ!Repeater 6000 wireless repeater is an update once you’ve logged on to your home Internet, you
of AVM’s popular FRITZ!Repeater 3000 model, and it can wander around the house with the gadget in
makes several advances on the older product. question without it leaving your router’s network and
Most importantly, the FRITZ!Repeater 6000 is Wi- joining the repeater’s and vice versa. It just works,
Fi 6 compatible. This new Wi-Fi standard is designed completely seamlessly.
for the modern network, where far more connected Last, but by no means least, it’s easy to set up.
devices are present than was the case just a few The repeater uses the Wi-Fi Protected Setup (WPS)
years ago. These days, as well as computers, mobile standard, so to connect it to your router, you simply
devices and smart TVs, you’re likely to have Internet press a button on each device. Your router’s settings The 6000 Mbit/s repeater is compatible
with the new Wi-Fi 6 standard.
radios, connected smart devices such as Amazon are copied to the repeater. And that’s it.
Echo and Apple HomePod, home appliances like a If your router’s Wi-Fi network struggles to reach
video doorbell, motion detectors or heating controls the furthest corners of your house, a repeater is
and more. Wi-Fi 6 is better designed to deal with a great way to overcome these problems. The
the congestion this implies. It’s fully backwards FRITZ!Repeater 6000 is an excellent option. It’s easy
compatible with older versions of Wi-Fi, so the to use, very capable and works efficiently.
repeater will work with your existing gear too. It
operates on three Wi-Fi bands working in parallel,
and automatically chooses the most efficient path to
your router.

It’s Wi-Fi 6. Repeat – it’s Wi-Fi 6...


As well as Wi-Fi, the FRITZ!Repeater 6000 has
two Ethernet ports for cabled connections, with
speeds of one and 2.5 gigabit speeds respectively.
This is also an improvement on its predecessor,
which offered two one-gigabit LAN ports. Another
improvement is the overall maximum throughput
speed, which at 6000 Mbit/s, is twice as quick as the

www.pclpublications.com 97
Airpulse P100X
Stereo Speaker
Stream music through Bluetooth, maybe from your new smartphone or tablet.

Info//
Platinum Audio Systems
Company
http://www.airpulseaudio.com
£499.99, $629, 599 €

A
irpulse’s latest offering, the P100X stereo clicky on-off dial. With a little tuning you have a fine
Bluetooth speaker, should appeal to those reproduction of rock and hip-hop by boosting the
who like their tech to be beautiful as well as bass, or add extra treble for classical or pop sounds.
practical. Inspired by traditional FM radios of old, it The volume is pretty good for a speaker set of this
has a gorgeous mesh finish at the front and back, size too. It will definitely fill a room, though it might
and an elegant cherry wood speaker casing at the not be enough for a party in a warehouse.
top and sides. Overall, its warm, rich sound should satisfy even
Sound-wise, it features a pair of custom-designed the most discerning audiophile, and its elegant good
10w tweeters and a 4.5-inch 40w mid-woofer, for looks will certainly please the decor-conscious.
60w in total. The tweeters use an oval-shaped
diaphragm to deliver a better high frequency
response, accurately reproducing even the highest
audio frequencies. The mid woofer is a 4.5-inch unit,
featuring a hard anodised aluminium alloy cone
suspended in a heavy, rigid cast magnesium alloy
frame. The device connects to your audio source via
Bluetooth v5.1, supporting the aptX HD codec, or
using the twin RCA Stereo ports at the back. RCA-to-
RCA and RCA-to-3.5mm leads are supplied.

Superb Sound
The stereo speaker unit is a meaty 30x18x20cm and
weighs 5.1kg, so it’s not designed to be portable.
Position it wherever you like in the house and plug
it into the mains. If your room is traditional and cosy
rather than modern and stylish, it should fit right in. It
comes supplied with a hand controller, so you don’t
even need to get out of your seat to operate it.
It has a neutral sound that doesn’t over-
emphasise one sonic area over another. It won’t,
for example, drown the mid-tones in bass, or mush
together the treble and vocals. If you want to tune
the sound, there’s a bass and a treble knob around The P100X has a beautiful, and slightly retro, appearance.
the front, as well as a volume control and a nice,

98 www.pclpublications.com
SOFTWARE REVIEWS

Affinity Photo, Designer


and Publisher
The award-winning creative app suite
fully integrated across Mac and iPad.

No subscription.

affinity.serif.com



www.pclpublications.com 99
SOFTWARE REVIEWS

Procreate Pocket
“All you need to paint is a few tools, a little instruction and a vision in your mind.”
– Bob Ross.

Info//
Savage Interactive Pty Ltd
https://procreate.art/pocket
£4.99

A
tablet is a near-perfect platform on which to express your fastest, 64-bit painting engine. Highlights include UHD canvases, up
artistic tendencies. Its large display and professional-quality to 16k x 4k, a Dark Mode interface, a QuickShape feature for creating
surface and capabilities make for an excellent drawing pad. A perfect shapes, 250 levels of Undo and Redo, a continuous auto-save
smartphone, on the other hand, is a little more difficult. But with the function, smudge sampling and 64-bit colour.
release of Procreate Pocket, artists can now unleash their talents on The minimalistic gallery screen opens up to display your chosen
the smaller screen. Don’t be fooled into thinking the iPhone version image, with a toolbar at the lower portion of the window that allows
of Procreate is a cut-down release; it’s not. In fact, it’s matched with you to access your collection of brushes and effects. Sidebars are
the iPad in terms of features, technicalities and abilities. present depending on the tool selected, allowing you to quickly
There are hundreds of handmade brushes available, alongside a tweak anything as needed. But overall, the screen doesn’t feel
suite of tools and the new Valkyrie Graphics Engine – the latest, and too cluttered by the wealth of options-within-options available.

Create stunning works of


digital art, on your iPhone.

100 www.pclpublications.com
SOFTWARE REVIEWS

Procreate Pocket is an impressive app. Unlock your inner artist, and get creating.

If, though, you do need to view the image as a and being able to share everything to any number
whole, then a simple four-finger tap will hide the of social media platforms as well as iTunes,
interfaces and on-screen accessories. Dropbox, iCloud and many more.
The sheer number of brushes available will have Procreate Pocket works like a charm. There’s
even the most critical of digital artist raising their only a slight hint of lag when applying some of
eyebrows. There are hundreds of them. And, within the more processor-heavy filters and features, but
each of the individual brushes, there’s dozens of not enough to have you flinging the device out
customisable settings – even the ability to create the window in frustration. One criticism, and this
your own custom brushes – plus, you’re able to is really stretching it, is that it’s possibly too big.
import Adobe Photoshop brushes. The wealth of There’s too much to choose from, so unless you
options is staggering, and can be quite bewildering really know what it is you want, you can spend
to the novice, and probably a little overwhelming more time scrolling through brushes, filters and
even to more advanced digital artists. whatnot than actually drawing or enhancing an
Want a brush with touch-up options to change image in the first place. That may seem like a
the skin tone of someone into a zombie? How rather pedantic criticism, but as we mentioned
about one that draws shapes all over the screen? earlier, you can feel a little overwhelmed by the
Needless to say, there’s something for everyone amount of choice available. Still, we’d probably be
here, you just need the time to scroll through and complaining if there was less choice.
test each to find what it is you’re looking for. So, to conclude, Procreate Pocket is an impressive,
There are tons of other elements too that could and powerful tool for the smartphone digital artist.
have us droning on for pages: Animation Assistant, Professionals and amateurs alike will find everything
Motion Blur filters, 25-layer blend modes, font they need within the confines of this app.
importer, what feels like an infinite numbers of
filters, isometric tools, time-lapse recording in 4k,

www.pclpublications.com 101
SOFTWARE REVIEWS

Splice – Video Editor & Maker


Create or edit your own videos, complete with music in no time at all.

Info// T
his is the perfect editor for anyone wanting this app, as there really is wealth of options
to put together videos quickly and easily. It to explore and tools to mess around with (the
takes literally just a few minutes to get the majority of which are behind a paywall, but are
Bending Spoons Apps IVS hang of using it, and you’ll be putting together your reasonably priced) as you learn some very useful
bendingspoonsapps.com own videos in next to no time. video editing skills and develop your style. Splice
Free Ease of use is everything in an app like this, and – Video Editor & Maker certainly won't appeal to
Splice manages to be flexible enough to create the professional, but for the new video maker, it is
good, professional-looking videos while keeping highly recommended.
everything so simple you can’t go wrong. You
can add videos and static pictures as well as title
pages. Choose from a variety of fades to move
from one to the next. You can add music tracks
from iTunes, record a voiceover or use the sound
from the videos themselves.
Adding and removing sections is easily
accomplished with a couple of button presses.
Click the preview button to view your progress and
when you’re satisfied hit export to save out your
masterpiece. It’s ideal for holiday videos, thank-
you messages or just a great little app to have fun
with. Let your creative juices flow with the very
comprehensive video editing suite and set of tools.
Unlike a lot of video editing software, Splice is
aimed at the beginner. Each new tool comes with a
tutorial and its ease of use means experimentation
is very much encouraged.
Experimentation is a fitting description for

102 www.pclpublications.com
SOFTWARE REVIEWS

Run off that lockdown weight and become the new special on the zombie menu!

I Info//
t’s always nice to come across an app that does During your run you’re regularly updated with
something a little bit differently, or takes an news of a zombie outbreak. You need to follow a
existing idea and puts its own unique spin on it. certain route to collect items. Every so often you’re Six to Start
Especially considering that everyone is talking about alerted that the zombie horde is after you. That’s zombiesrungame.com
Netflix’s new undead action romp, Army of the Dead. when you have to break into a sprint; a bit like in a Free
Zombies, Run! does exactly that, and it helps you to spinning class when you do bursts at top speed. If
get fit as well. It’s part adventure game, part fitness you don’t go fast enough, the zombies catch you
app and part interactive story. The concept might up and take some of the virtual ‘stuff’ that you’ve
sound a little strange at first but it makes perfect collected. This is important as it’s used when
sense when you start using it, so you just have to you complete your run to build a virtual zombie-
trust us that it works. sanctuary in the app. The ultimate goal is to build up
Zombies, Run! is an app designed to help people your sanctuary and get as many people as possible
who want to run, but lack the motivation to actually to join it. Each run is a different ‘mission’ with slightly
get out there and do it. The incentive in this case is to different goals that need to be accomplished.
turn the whole thing into a kind of interactive game. It’s a really cool and original way to make running a
Based on GPS data, the app sets a run route for you. bit more interesting. The subscription price is very high
All you need to do is plug in your headphones, hit for an app of this type, but if you’re willing to shell out
Start and off you go. the necessary cash, you’ll have a blast with it.

www.pclpublications.com 103
SOFTWARE REVIEWS

Radio Garden
I’d like to teach the world to sing...

Info//
S
ites that collate Internet radio stations to explore more stations from the country of the
aren’t exactly thin on the ground, but Radio station that’s currently playing and more.
Radio Garden BV
Garden does it differently. Instead of listing
http://radio.garden
broadcasters by genre or country, it locates them
Un-wired for sound
Free (IAP for mobile devices) Radio Garden offers an alternative way to explore
on a globe which you can rotate on the screen, and
Internet radio. It’s great fun to find an obscure,
zoom in and out of for a better view. Every shining
distant part of the world which you’ll never see in
dot on the map is a radio station (or for pedants, an
real life, and listen to a local station while taking
Internet streaming broadcast). Click on a dot, or drag
a ‘drive’ around town using Google Maps’ street
the globe until it’s in the centre of the circle in the
view. It’s like going on a virtual holiday. There
middle of the screen, and that station plays.
are services found all over the world, in every
Using the controls at the foot of an smartphone
language imaginable. In our tests, we had no
screen and in the bottom-left on an tablet or
problems with buffering or poor reception either.
desktop, you can play and pause the stream, or
If you’re a fan of Internet radio, we definitely
move to the next or previous local station. Tap the
suggest you give Radio Garden a try; you’ve
heart to add it to your list of favourites, and the three-
nothing to lose. It’s available through a free,
dots icon lets you share a station or visit its website.
ad-supported app for mobile devices (an in-app
This window also shows the name and location of
purchase removes the ads), and on the desktop,
the station. The collapsible window above these
simply open the service in your web browser;
controls gives more options, such as: browsing and
http://radio.garden.
search options, access to your favourites, the chance

If you know of a station that isn’t on Radio Garden, tell them


about it.

104 www.pclpublications.com
SOFTWARE REVIEWS

iMazing 2
The smarter way to manage your iOS devices.

i Info//
Mazing is a device management tool for all iOS simpler with iMazing. Again, you simply drag and
and iPadOS devices. Open iMazing on your drop them. Ringtones can also be added in this
desktop and connect an iPhone, iPad, iPod touch, way. Its management of the Music app gives you the DigiDNA SARL
Apple TV or even a classic iPod, and you can explore drag-and-drop simplicity you’ve always wanted for https://imazing.com
and organise its contents with a far greater degree your iOS device, and it works for movies and other From £29.99, $40.75, 35,99 €
of control than macOS natively allows. Various video files too.
price points are available, depending on how many In this short review, we’ve barely scratched the
mobile devices you wish to use with it. surface of what iMazing can do. It’s a comprehensive
The app can back up your device to your management system for mobile devices which puts
computer, without deleting previous backups. you in control of your gear in a way macOS and the
These backups are encrypted, and unlike regular Music app never could. If you’re keen to get more
backups, they can be stored on any connected from your iPhone or iPad, without jailbreaking the
hard drive or NAS drive – it doesn’t have to be your device, iMazing is a must.
boot drive. Backups can be scheduled and carried
out automatically, and you can review and restore
their contents just like you can with Time Machine
backups. You can also restore your device in its
entirety from an iMazing backup, quickly and easily.

Control freakery
Messages stored on your iPhone can be reviewed
on your Mac, including all SMS, MMS and iMessage So many things can be transferred
chats; and all attachments. You can then save seamlessly between your devices
out conversations as a PDF, a spreadsheet or
text document, and it also lets you print them
directly from iMazing. WhatsApp messages, Notes,
Calendars, voice recordings and more can also be
Contacts can be copied from one
backed up and reviewed in this way. Contacts can device to another using drag and drop.
be copied from one device to another by simply
dragging and dropping, and phone records and
voice mails are preserved too.
Copying PDFs and ePubs to the Books app is far

iMazing offers far wider backup options than macOS. iMazing even works with iPods. Remember them?

www.pclpublications.com 105
SOFTWARE REVIEWS

Impressive
Photography Apps
The smartphones have amazing cameras. If you want to make the most out of their fabulous photography
capabilities, take a look at ten of the best third-party photography apps for smartphone and tablet. Whether
through taking more impressive shots or editing them to really bring out the best in your photos.

Camera+ 2
Developer: LateNiteSoft S.L, http://latenitesoft.com
Price: £2.99, $2.99, 3,49 €

Camera+ 2 is a complete overhaul of the popular photography app Camera +. It’s compatible
with smartphone, tablet and iPod touch, and gives far more control over your shots than the
standard OS Camera app. You can capture photos in RAW mode, set shutter speed, ISO and
white balance, and in dual camera iPhones, use the impressive depth capture mode. You can
also set it to only trigger the shutter when the device is stable, or when it detects a smile.

Halide Camera
Developer: Chroma Noir LLC, https://halide.cam
Price: £5.99, $5.99, 6,99 €

Another replacement for the standard OS Camera app, Halide intelligently optimises ISO
and shutter speeds for sharp, clean photos. The interface is designed around touchscreen
gestures, and is intuitive to use. On the iPhone X and later, it’s designed for use with just one
hand. It gives you more control over your photos too, with a powerful manual focus and full
manual controls including shutter speed, ISO and white balance.

ProCam 6
Developer: Samer Azzam, www.procamapp.com
Price: £5.99, $5.99, 6,99 €

This Camera replacement offers a range of shooting modes, including Photo, Night Mode,
Burst Mode, Slow Shutter, Portrait Mode, 3D Photos, Video, Time Lapse and more (some
modes require dual cameras). It boasts an anti-shake feature to cut out those blurry snaps,
and has a wide range of manual controls not present in the Camera app.

Slow Shutter Cam


Developer: Cogitap Software, www.cogitap.com
Price: £1.99, $1.99, 2,29 €

This very affordable camera app is designed for long-exposure photographs, of the kind
previously only possible with a DSLR. It’s great for creating effects such as motion blur and
light trails, and also for taking photos in low-light situations. It offers manual ISO controls,
and an unlimited shutter speed for full control over your slow shutter pictures.

106 www.pclpublications.com
SOFTWARE REVIEWS

Manual – RAW Camera


Developer: Will Global, http://shootmanual.co
Price: £3.99, $3.99, 4,49 €

This advanced camera app’s features include an EXIF viewer, live histograms, focus zoom,
an optional delayed shutter for long exposures and live-monitored auto exposure levels. It
offers full control over your camera settings, including Shutter, ISO, White Balance, Focus
and Exposure Compensation. It requires an iPhone 8 or later.

Snapseed
Developer: Google LLC, www.google.com
Price: Free

This popular photo editing app from Google offers a wide range of tools and filters. It can
open RAW files as well as jpegs, and its filters include Vignette, where you can blur the edges
of a picture, Healing to remove blemishes and flaws, and a lens blur to add bokeh effects to
your snaps.

Retrospecs
Developer: John Parker, https://8bitartwork.co.uk
Price: Free (IAP for more filters)

Ever wondered what your photos would look like if they were digitised onto a retro
computer such as the Spectrum, Commodore 64 or Amiga? No? Us neither, but we had
great fun finding out. Retrospecs takes you back to the 70s, 80s and 90s, with a series
of fun filters designed to let you reproduce computers of old. It has manual adjustment
capabilities too.

Affinity Photo for tablet


Developer: Serif Labs, https://affinity.serif.com
Price: £19.99, $19.99, 21,99 €

If you want a fast, powerful editing suite that can give professional results, look no further
than Affinity Photo for iPad. It has full layer support, pro-level image processing, amazing
retouching and correction tools and can save in a range of formats. This is not a collection of
filters – it’s a full image processor, and a bargain at the price.

Photoshop Fix
Developer: Adobe, www.adobe.com
Price: Free, IAP for more storage space

Photoshop is unquestionably the most famous photo editor, but it’s also one of the most
expensive. Not so this free app for the tablet. Fix delivers features to mobile devices that
were previously available only in the main Photoshop suite. Powerful and extremely well
designed, you’ll soon be touching up your photos like the pros.

Facetune 2 for tablet or smartphone


Developer: Lightricks Ltd, www.facetuneapp.com
Price: Free, IAP

This highly respected app is built for polishing and fixing selfies and other face pictures. It’s
extremely powerful, yet very easy to use. Overlaid tutorial tips show you what can be done
as you work on your photo; make the teeth whiter, get rid of bags from under your eyes,
rejuvenate your skin and more. It’s free, with in-app purchases opening new features.

www.pclpublications.com 107
GAMES REVIEWS

Alien: Isolation
The perfect showcase for your Smartphone’s awesome screen.

Info//
Feral Interactive Ltd
£12.99, $14.99, 14,99 €

In the words of Private Hudson


“That's it, man. Game over, man.
Game over!”

R
idley Scott’s original Aliens from 1979 However, 2014’s Alien: Isolation from SEGA and
was a ground-breaking piece of cinema. Creative Assembly hit the nail on the head. Isolation
Set within the claustrophobic confines brought Giger’s xenomorph to life for the PC, and
of a spaceship, the crew are hunted by an alien it scared the socks off us. Fast forward, and we can
creature of immense death-dealing impressiveness. now appreciate that terror on the smaller screen
It was tense, scary as hell and the feeling of thanks to Feral Interactive, with one of the best
absolute terror seeped through the screen as the ports we’ve experienced in quite some time.
protagonist, Ripley, tries to flush the beast into the
depths of space.
Sadly, that sense of terror had never really been Isolated and Alienated
conveyed through gaming. True, there have been Alien: Isolation is set 15 years after Scott’s Alien.
several Aliens-based games in the past, for all manner You take on the role of Amanda Ripley, Ellen
of systems (one of our favourites was a Doom Aliens Ripley’s daughter. Amanda discovers that Ripley’s
mod, from 1994), and we did have space-based horror flight recorder has been recovered, and travels
in the form of System Shock and Dead Space, but the to the Sevastopol Space Station to claim it for
Alien franchise always felt a little flat. herself. But all is not well on board.

Wonderful atmospherics make for


some terrifying jump scares.

108 www.pclpublications.com
GAMES REVIEWS

And that would be me dead


The Sevastopol is a labyrinth of darkened poorly lit corridors only to come face to face with
corridors, service tunnels, ventilation ducts and the alien is truly one of gaming’s greatest moments.
other cramped and totally horrible places where It’s the intense pressure that gets to you. Armed
something unpleasant can jump out at you. It’s with something that wouldn’t scare a hamster and
in the process of being decommissioned, and slowly walking down a corridor with your motion
as such, most of it is falling apart or not working detector in hand, side-stepping bodies littering
correctly; lights flicker, doors malfunction; you get the floor, makes you sweat. You find yourself
the picture. holding your breath as the motion detector
This ported mobile version comes complete suddenly springs into life, and it’s real panic as
with all the available DLC packs, including the you quickly realise that whatever it is that’s being
Crew Expendable, Last Survivor and Survivor detected is heading toward you.
modes. You can play with on-screen joystick There aren’t many games that are this
controls, use a gamepad or wireless mobile OS- immersive, making you feel the anxiety of moving
compatible keyboard and mouse. around a dilapidated space station while being
hunted. Hats off to Feral Interactive, they’re
responsible for my Fitbit nearly overheating while
Techno Terror measuring my heartbeat.
There’s no loss in technical quality either. And for the measly sum of £12.99, you too can
Graphically, Alien: Isolation is superb, and through a be scared witless. Stick some headphones on, turn
wonderful mix of audio and visual atmosphere, the off the lights and have a defibrillator to hand just
stark horror of slowly winding your way around the in case. Alien: Isolation is coming for you.

Play through the available DLC and


different modes.

www.pclpublications.com 109
GAMES REVIEWS

A knee to the face, then get thrown over the shoulder. Beautiful.

I Info//
blooming love Double Dragon. Back in the late There are different modes, too. Arcade plays
Eighties, at the local arcade – a dingy, dishevelled with a single credit, where you fight to get highest
DotEmu
dive, complete with sticky carpet and drenched score, and Story Mode unlocks stages and
£0.89, $0.99, 0,99 €
in eye-watering neon – my mate Daz and I would achievements. Mobile, Original and Expert difficulty
force-feed ten pence pieces into the Double Dragon modes keep you entertained, and getting your
arcade machine and settle in for an afternoon of name on the leaderboard is just as tantalising.
cooperative digital violence. It was superb. For only 89 pence, the Double Dragon Trilogy is
Imagine how happy I was to get my hands on the worth every penny. It’s splendid, and we loved it.
complete trilogy on the iPad. Sadly, Daz and I have
parted ways in the years since 1987, but these days I
have a couple of children who can help me take on
the bosses and finally rescue poor old Marian from
the clutches of the Black Warriors gang.
Often, when it comes to arcade conversions
for mobile devices, the end result is far from what
you fondly recall as a youth. However, developers
DotEmu have done a wonderful job of recreating the
style and ambiance of the original arcade machines.
Graphically, it’s as you remember but with a
slightly more polished sheen to it. There’s still
the clunky arcade graphics, but this time with
smoother edges, and the end result is still the
same. It’s a near-perfect port of the original. The
controls are a little tedious to get to grips with, but Here we go, the first gang member to
taste your wrath!
after a few rounds you soon get used to them. Grab
a friend, and the pair of you can Bluetooth your
way through the gang along to the original eight-bit
soundtrack, or choose a newer remastered version.

A wonderful blast from the past, in all its arcade glory.

110 www.pclpublications.com
GAMES REVIEWS

Keeping it (looking) real, 1990s style!

P Info//
art game, part interactive movie, when up even in its original form.
Another World was first released for the Amiga The usual control issues are present,
DotEmu
it was more than just another game. It was a unfortunately, but they’re quickly dispatched by
www.dotemu.com
real interactive experience. Rather than falling into using a compatible controller, if you have one.
£3.49, $3.99, 3,99 €
one of the established genres of the time, Another Developers still haven’t figured out a way to
World was neither a puzzle game, a shoot-’em-up perfectly recreate micro-switched joystick controls
nor a platformer, but it was all of these and more. using a touchscreen. This can make sections where
Playing it now it’s easy to forget how precise positioning and timing are required harder
revolutionary it was at the time. The spookily than they ought to be, and you need plenty of do-
realistic sprite animation still looks very nice, but it overs for this reason.
was gob-smacking in 1991. The game begins with a If you didn’t experience Another World in its
scientific experiment gone wrong, which transports original format, it’s still a great little game but you
the main character to a strange, dream-like world won’t understand quite how fantastic and ground-
and so begins the adventure where you take on breaking it actually was. If you did have the pleasure
challenge after challenge as you try to stay alive of playing through it back in the day, you’ll relish the
and figure out a way to get back home. You even opportunity to relive it in all its glory. The slightly
make a friend along the way, and despite the lack choppy controls only marginally mar this bona-fide
of dialogue, the game manages to conjure a real all time classic.
emotional connection between the two characters.

Thirty Years On...


The mobile version comes with polished, enhanced
graphics, but with the option to switch back to
the original style. The enhanced version doesn’t
change the overall look, but adds some depth to
the backgrounds, which is a good thing. Although
the highly stylised nature of the visuals has much to
do with the limitations of the original hardware for
which it was designed, this is all part of what gives
the game its unique atmosphere and it still stands

Switch between retro and HD graphics.

www.pclpublications.com 111
GAMES REVIEWS

Grand Theft Auto


Liberty City Stories
What you can do on your new smartphone is a crime.

Info//
Rockstar Games
www.rockstargames.
com
£5.99, $5.99, 5.99 €

I
t’s hard to believe Grand Theft Auto III is well excitement about the promise of a fully functional,
over 20 years old. It’s also hard to imagine how blur-free and playable version of the Sony PSP’s
the games industry would look without this overlooked (and rightly so), GTA Liberty City Stories
iconic brand that transcends video gaming. Even for mobile OS's. After all, nostalgia can be a double-
non-gamers are familiar with the title, although edged sword when revisiting such a revered classic,
often for the wrong reasons. Controversy! Violence! but possibly more so when said port could offer
Adult content! Yet GTA didn’t become an institution redemption! Will this reworked version of Liberty City
because of its controversial storylines. It invented Stories remain the weakest release in the monster
the ‘sand box’ genre which has changed the face of franchise, or be elevated to new highs?
gaming in subsequent years, with the growth and
development of the franchise to the levels one would
once question possible with the masterful GTA 5 and Up, up and away!
the devastating badness of the much anticipated Thankfully, the answer is the former. In fact
and much savaged Grand Theft Auto Collection. it’s a testament to how solid the mechanics of
Despite the fantastic ports of Vice City and San the original game were that the structure and
Andreas, there was enormous trepidation and progression still stands up. It looks even better

You don’t need to worry too much


about squashing pedestrians.

112 www.pclpublications.com
GAMES REVIEWS

than it did on the PSP and PlayStation 2. Textures on backstory and dialogue still impress here. You get to drive some awesome cars,
are smoother and more detailed, pop-up is non- The many fantastic cut scenes are snappier and while ignoring the rules of the road.
existent and the freedom to roam around this designed to move you swiftly into the next mission,
living world is a joy. Plus no motion blur! Things which is ideal. In fact, many would argue that later
also play far better and more reactively than ever GTA games are too serious and dialogue-heavy.
before. The original control scheme has been This is all about playability and having fun. Younger
admirably tweaked to fit the touchscreen and the players brought up on the current generation of
game is so much better for it. Driving, on foot or consoles may feel it lacks sophistication, but this
during combat, you’re in complete control. does it a disservice. In terms of mobile gaming,
The mission and story progression keep you this is above and beyond most of what’s currently
hooked, and Rockstar’s talent for character creation available, outside of its franchise kin.
and narrative are evident here. The story is set Anybody who experienced GTA Liberty City
before the events of GTA III, but still within the Stories first time around will relish the opportunity
criminal underground. The voice acting is fantastic, to revisit it. This is an epic game in concept, scale
as is the script, mixing the right amount of clichés and execution. If you were too young to play it in
with belly laughs and a few neat plot twists. All of 2001, now’s your chance. The game design isn’t
which is to be expected, of course. Alas, one shock as revolutionary as it was, or even close to what
is the rather disappointing soundtrack. Not only is has become, but it’s still a forgotten great with
was the original lacking in quality, the mobile port awesome pacing and storytelling.
has seen a large percentage deleted. Whether or not you played this game in its
disappointing original form and want to see how
it should’ve been done, it’s simply an unmissable
You talkin’ to me? GTA experience that no one with the remotest
In terms of gameplay, there’s no real levelling interest in the series should ignore. This isn’t the
system for the main character (á là San Andreas), best GTA game, not even the best one on the iOS,
but he acquires new and better weapons along but this is the best version of GTA Liberty City
the way to make him more formidable. While the Stories you can play.
cinematic nature of the series later expanded with
the hardware’s processing power, heavy emphasis

The tasks you’re set to accomplish to advance your criminal career are as controversial as ever.

www.pclpublications.com 113
GAMES REVIEWS

Retro shoot ‘em-up action has found a new home; in your pocket!

T
engai or Sengoku Blade as it is know in its
homeland, Japan, is a horizontal scrolling
subtitle. While stepping away from the traditional
outer space or war zone setting, the game takes
Info//
S&C Ent. Inc
arcade shoot-‘em-up which was released in players back into ancient Japanese folklore, battling
www.sncgames.com
arcades in 1996; and via several excellent home ports demons, evil magic and steampunk robots of various
Free
at the time. Yet this mobile conversion somehow sizes; and is all the better for it. The unique gameplay
feels the most fitting of the home releases. setting also reaches out into the presentation,
Allow me to explain. As a long-time fan of the design and the fantastic soundtrack. The gameplay
genre, I have always experienced issues with lifespan is exactly what one would expect from the genre;
vs price when it came to purchasing stand-alone collectable power-ups to advance your weapon, a
releases. Numerous shooter collections litter my selection of characters each with differing skills and
games collection, but very few stand-alone packages abilities and huge mid and end-of-level bosses. But
join them. This is far from a criticism, but the genre its honed to near-perfection.
itself lends itself well to short bursts of intense Tengai delivers everything you could hope for;
gameplay coated in rich, over-the-top visuals, sonics a fast-paced, over-blown, action-packed gameplay
and a pumping soundtrack. This is perfect arcade experience with a rich coating of flamboyant visuals
fare, as a handful of credits offer fans their required and inventive character designs, accompanied by a
fix of shmup fun. As a full-priced console game or blistering soundtrack. Shmup brilliance!
a staggeringly high-priced Japanese import game,
the value for money didn’t stack up. Yes, I was a very
boring child too!
Over the years, the App Store has racked up a
fantastic collection of classic ’80s and ’90s shoot-
‘em-ups. The easy access of the platform and the
auto-fire/touch controls combination work in a way
that will delight fans and create a host of new ones.
Tengai has all the ingredients to live up to its

114 www.pclpublications.com
GAMES REVIEWS

BADLAND, Game of the Year Edition


Join us on a fairy tale adventure through magical forests littered with circular saws!?

B
Info// ADLAND is a beautifully designed side-
scrolling action adventure puzzleplatformer
unreachable areas. Selecting the incorrect power or
contraption could make it impossible to complete
Frogmind
that takes place in an atmospheric forest the level, so your decision is vital. There are over a
www.badlandgame.com
packed full of deadly traps you must navigate hundred unique levels to complete, and each one
£0.99, $0.99, 0,90 €
through to reach the end of each level. The game is offers a totally different experience.
controlled by using one finger to guide the peculiar There are so many challenges in each level that
furry character through the treacherous BADLAND, it will undoubtedly take you several attempts to
much like the highly addictive 2D Helicopter PC figure out exactly what to do. This is where trial and
game if you recall, or the side-scrolling sections in error and the addictiveness seriously take control.
classic Mario. However, this is a great deal more The gameplay is excellent, so you’d imagine the
in-depth and obviously visually superior. visuals would let it down in some way. But this is
The screen automatically scrolls from left to definitely not the case! The art style is actually what
right. You simply tap your device's screen in order grabs you the most, using vivid colours for each level
to cause the furball to rise higher, thus avoiding the background and dark silhouettes for the characters
many traps and obstacles in your path. Releasing and foreground. It looks stunning on a big screen via
your finger causes him to drop back down. There your AppleTV. This truly is a fantastic game.
are many power-ups available in each level, which There is also a local online multiplayer feature
you need to collect (or avoid, depending on what which allows up to four players to battle it out on
traps are coming up) in order to complete each the same device. This feature is all about survival
stage. For example, some make you larger or – steal power-ups, hinder opponents, and survive
smaller, thus causing you to become heavier or to the end. Should you tire of the levels that are pre-
lighter, affecting whether you can squeeze through installed, why not build your own with the fantastic
small spaces; some transform you into a ball, level editor. When complete your creations can
allowing you to roll across treacherous grounds; shared with the world and the world’s shared with
and others turn you invisible. you, giving you near-endless gameplay options.
There are numerous contraptions to use (or This should be retitled to VERYVERYGOODLAND!
avoid) too, such as circular saws which invariably kill
you, or catapults which propel you up to otherwise-

www.pclpublications.com 115

   
 

www.pclpublications.com
঒ন঻ষ঍শশসন
Guess who is dropping by next issue? Come
back for issue six of ইoding ঙser for even
more essential coding tips and tricks from our
team of experienced industry insiders. We will
be covering all you need to know on Linux in the
expert tutorials that you can expect from us.
঺঺঺ॲ঳দয঳সথযবদতষবল঱শॲদলর
On Sale June 2023 via digital platforms


  

 )>97<;8?;0?=4>?9>3<9>5?4:95*:9>(? =?9>.:<87?=4>?13924:7>97?7;6> !4<7?$:1>923=?%<.<=>5?13-6<2:=<;8?<7?0366/?<85>1>85>8=?:85?:7?7324


9>71;87<-<6<=/?=;?5>=>9.<8>?=4>?73<=:-<6<=/?;0?=4<7?-;;'?:85?<=7?2;8=>8= 5;>7?8;=?8>2>77:9<6/?9>06>2=?=4>?)<>*7?;9?;1<8<;87?;0?=4>?19;532>97?;0
"     "!   
0;9?*4:=>)>9?1391;7>(?&8/?<.:,>7?9>19;532>5?;8?=4>?09;8=?2;)>9?:9> &117?;9?19;532=7?2;8=:<8>5?*<=4<8(?!4<7?13-6<2:=<;8?<7?8;=?>85;97>5?;9
$3-6<74>5?-/ $:1>923=?%<.<=>5 7;6>6/?0;9?5>7<,8?1391;7>7?:85?:9>?8;=?9>19>7>8=:=<)>?;0?2;8=>8=(? :77;2<:=>5?<8?:8/?*:/?*<=4?:8;8<2:6?%=5+?$/=4;8+?!4>?%<83
#:8:,<8,?5<=;9 :.>7?:6> >?:5)<7>?:66?1;=>8=<:6?-3/>97?=;?24>2'?6<7=<8,?19<;9?=;?13924:7>?0;9 ;385:=<;8+?!4>?":71->99/?$<?;385:=<;8+?&"#?;65<8,+?>-<:8?$9;>2=+
$9;532=<;8?<9>2=;9 #:9'?&/740;95? 2;80<9.:=<;8?;0?:2=3:6?2;8=>8=(?&66?>5<=;9<:6?;1<8<;8?4>9><8?<7?=4:=?;0?=4> %<83?#<8=+?#<29;7;0=+?%>8;);+?>66+?>*6>==$:2':95+?&116>?:85
5<=;9 :.>7?:6> *9<=>9?:7?:8?<85<)<53:6?:85?<7?8;=?9>19>7>8=:=<)>?;0?=4>?13-6<74>9?;9?:8/ :.738,?;9?:8/?:77;2<:=>?;9?:00<6<:=>?2;.1:8/(?&66?2;1/9<,4=7+?=9:5>
$9;532=<;8?#:8:,>9 #:9'?&/740;95 ;0?<=7?:00<6<:=>7(?!4>9>0;9>?=4>?13-6<74>9?4;657?8;?9>71;87<-<6<=/?<8 .:9'7?:85?9>,<7=>9>5?=9:5>.:9'7?0;9?=4>?9>71>2=<)>?2;.1:8<>7?:9>?
>7<,8 :.>7?:6>+?#:9=<8? .<=4+?#:9'?&/740;95? 9>,:95?=;?>5<=;9<:6?;1<8<;8?:85?2;8=>8=(?$:1>923=?%<.<=>5?9>7>9)>7?=4> :2'8;*6>5,>5(?">6>):8=?,9:14<2?<.:,>9/?9>19;532>5?*<=4?2;39=>7/?;0
5<=;9<:6 :)<5?:/*:95+?:.>7?:6>? 9<,4=?8;=?=;?->?4>65?9>71;87<-6>?0;9?:8/?.<7=:'>7?;9?<8:2239:2<>7?0;385 %>8;);+?>*6>==$:2':95+?>66+?#<29;7;0=+? :.738,+?%<83?#<8=+?& &+
<,<=:6?5<7=9<-3=<;8?-/ <8<;+?$;2'>=.:,7+?">:56/? ?#:,=>9 *<=4<8?=4>?=>=?;0?=4<7?13-6<2:=<;8(?!4>?13-6<74>9+?>5<=;9?:85?=4><9 :85?&116>( &55<=<;8:6?<.:,>7?2;8=:<8>5?*<=4<8?=4<7?13-6<2:=<;8?:9>
9>71>2=<)>?>.16;/>>7?;9?:00<6<:=>7?*<66?8;=?:22>1=?9>71;87<-<6<=/?0;9 9>19;532>5?385>9?6<2>87>?09;.?743==>97=;2'(2;.(
 © ;1/9<,4=?$:1>923=?%<.<=>5(?&66?9<,4=7?9>7>9)>5( 6;77+?5:.:,>+?<839/?;22:7<;8>5?=;?:8/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?=3=;9<:67+?=<17+?,3<5>7?*<66?*;9'?;8?>)>9/? 8;=?-3/?=4<7?13-6<2:=<;8( ;9?.;9>?<80;9.:=<;8?>.:<6?,:6>12613-6<2:=<;87(2;.

You might also like