80 likes | 206 Views
T eaching L ondon C omputing. Programming for GCSE 1.2 Writing Python Scripts. William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London. Aims. Writing Python program Creating files Comments Layout Using ‘print’. Python Program.
E N D
TeachingLondon Computing Programming for GCSE1.2 Writing Python Scripts William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London
Aims • Writing Python program • Creating files • Comments • Layout • Using ‘print’
Python Program • Python programs can be very simple • File (best to name it with extension .py) • Much simpler than Java (or C♯) print(”hello”)
Comments • Comment explain a program • Comments can be used to help plan a program # Thisprogram prints a greeting print(”hello”)
Layout • An important feature of Python • Indentation matters! Always start in the same column
The ‘print’ function • The ‘print’ function is used to output a string • In these examples • The print function has two strings or an expression • Note the spaces • Both statements output the same thing print(“hello“, “world“) print(“hello“ + “ hello“)
Printing Numbers • Print can also output a number • Example >>> print("Average is", (30 + 40)/2) Average is 35.0
Summary • A Python program is a file containing statements • Simple! • ‘print’ for output • String and numbers