Introduction to Programming
Development Programme 2020
Outline
1. Introduction
2. Printing output
3. Comments
4. Variables
5. Reading Inputs from Keyboard
6. Mathematical operations
7. Loops
8. Functions
9. Making decisions (if)
10. Exercises
Printing output
Print() function is used to print data in a human-readable form
How to print something without a newline in Python?
Comments
• Adding comments is a good habit in programming.
• It improves readability of the code.
• In Python, comments start with a #
• Python will ignore the comments and will not execute them.
What is the colour used in IDLE to display comments ?
Variables (1)
• A variable is the name for a place in the computer’s memory where
you store some data which can be treated as containers for storing
data values
• There are different data types
Variables (2)
Variable naming rules
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and
underscores (A − z ,0 − 9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three
different variables)
Reading Inputs from Keyboard
• The function input() can be used to read input from the keyboard.
• The input value is always a string.
• If we need numbers we need to convert strings to numbers. We can
do that as following.
Mathematical operations (1 of 2)
Arithmetic Operators and Comparison Operators
Mathematical operations (2 of 2)
• Refer the documentations for math and cmath modules and the
examples demonstrated during online sessions.
• https://docs.python.org/3/library/math.html
• https://docs.python.org/3/library/cmath.html
Loops
• Programming languages provide us with the concept of loops which
helps us execute some task n number of times where n can be any
whole number.
Loops
Loops: Scope of the code
• Python relies on indentation (whitespace at the beginning of a line) to
define scope in the code.
• Other programming languages often use curly-brackets for this
purpose.
• Nested Loop Example
Functions
• A function is a block of code which only runs when it is called.
• You can pass data (known as parameters) into a function.
• A function can return data as a result.
• We can use functions in our program to reduce repetitive codes.
Making decisions (if)