You are on page 1of 14

Introduction to Computing

ES102 Fall 2015

Welcome to students of 2015 batch


In ES 102, we will learn the basics of programming. We will use Python as our
programming language. This course is aimed at students with little or no
programming experience. The course consists of lectures and lab sessions.
Instructors:
Theory : Krishna Prasad {kprasad@iitgn.ac.in}
Lab: Shanmuganathan Raman {shanmuga@iitgn.ac.in}
General Information
Textbook (Theory & Python Programming) :
http://www.greenteapress.com/thinkpython2/
Exercises : How to solve it by computer (R.G. Dromey)
Lab : How to solve it by computer (R.G. Dromey),
http://introcs.cs.princeton.edu/python/Introduction to Programming in Python : An
Interdisciplinary Approach by Robert Sedgewick, Kevin Wayne, Robert Dondero
Evaluation : 50% Theory + 50% Lab
Theory Part : 15% midsem +15% endsem + 20% assignments, surprise quizzes =
50%
Lab Part : 10% lab performance, 20% Lab Quizzes (5), 20% Final lab exam.

Course Website
https://classroom.google.com code:
k17sny
Think Python 2 - How to think like a computer
D2
D3
Lab Sec-1 Lab Sec-2
scientist

Wed
Thu
Fri
Fri
9:00-9:55 10:00-10:55 1:30-3:30 3:30-5:30
Week 1
02/09/2015 03/09/2015 04/09/2015 04/09/2015
Week 2
09/09/2015 10/09/2015 11/09/2015 11/09/2015
Week 3
16/09/2015 17/09/2015 18/09/2015 18/09/2015
Week 4
23/09/2015 24/09/2015 25/09/2015 25/09/2015
Mid sem recess 30/09/2015 01/10/2015 02/10/2015 02/10/2015
Week 5
07/10/2015 08/10/2015 09/10/2015 09/10/2015
Mid sem Exam 14/10/2015 15/10/2015 16/10/2015 16/10/2015
Week 6
21/10/2015 22/10/2015 23/10/2015 23/10/2015
Week 7
28/10/2015 29/10/2015 30/10/2015 30/10/2015
Week 8
04/11/2015 05/11/2015 06/11/2015 06/11/2015
Week 9
11/11/2015 12/11/2015 13/11/2015 13/11/2015
Week 10
18/11/2015 19/11/2015 20/11/2015 20/11/2015
Week 11
25/11/2015 26/11/2015 27/11/2015 27/11/2015
Week 12
02/12/2015 03/12/2015 04/12/2015 04/12/2015

Expressions, conditionals
Iterations
Functions, return values, Recursion
Strings, Lists
Exercises
Sorting
Searching
Exercises
Exercises
Dictionaries
Tuples, Files
Revision

Introduction to Computers

What is a computer?
Examples of computing devices
Input devices, output devices
What are things you can do with a computer?
Playing Music requires commands to be given to a particular
software
Hardware Inside the computer
Representation of information in binary format bits and bytes
Black and White, Gray Scale, and Color Pictures
decimal and binary numbers
What is a Program?
Program as a set of precise, unambiguous instructions in a
specific order
Interpreters, compilers
Variables and constants, evaluation of a function

Compilers and Interpreters

What is a Program?
input: Get data from the keyboard, a file,
or some other device.
output: Display data on the screen or
send data to a file or other device.
math: Perform basic mathematical
operations like addition and multiplication.
conditional execution: Check for certain
conditions and execute the appropriate
code.
repetition: Perform some action
repeatedly, usually with some variation.

Python as a calculator
Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

In interactive mode, you type code and the


interpreter displays the result:
>>>
2
>>>
42
>>>
42
>>>
42
>>>
42
>>>
4

1 + 1
40 + 2
43 - 1
6 * 7
6**2 + 6
6 ^ 2

>>> 84
42.0
>>> 85
42.5
>>> 85
42
>>> 85
>>> 1

/ 2
/ 2
// 2
% 2

Operator Precedence
PEMDAS
Parentheses have the highest precedence and can be used to
force an expression to evaluate in the order you want. Since
expressions in parentheses are evaluated first, 2 * (3-1) is 4, and
(1+1)**(5-2) is 8. You can also use parentheses to make an
expression easier to read, as in (minute * 100) / 60, even if it
doesnt change the result.
Exponentiation has the next highest precedence, so 2**1+1 is 3,
not 4, and 3*1**3 is 3, not 27.
Multiplication and Division have higher precedence than
Addition and Subtraction. So 2*3-1 is 5, not 4, and 6+4/2 is 8,
not 5.
Operators with the same precedence are evaluated from left to
right (except exponentiation). So in the expression degrees / 2 *
pi, the division happens first and the result is multiplied by pi. To
divide by 2*pi, you can use parentheses or write degrees / 2 / pi.

Values and Types


>>> type(2)
<class 'int'>
>>> type(42.0)
<class 'float'>
>>> type('Hello, World!')
<class 'str'>

>>> type('2')
<class 'str'>
>>> type('42.0')
<class 'str'>

Type Conversion
>>> int('32')
32
>>> int('Hello')
ValueError: invalid literal for int(): Hello
>>> int(3.99999)
3
>>> int(-2.3)
-2
>>> float(32)
32.0
>>> float('3.14159')
3.14159
>>> str(32)
'32'
>>> str(3.14159)
'3.14159'

Variables
>>> message = 'And now for something completely different'
>>> n = 17
>>> pi = 3.141592653589793
>>> type(message)
<class 'str'>
>>> type(n)
<class 'int'>
>>> type(pi)
<class 'float'>

>>> miles = 26.2


>>> miles * 1.61
42.182
>>> x = 5
>>> x**2 - 3*x + 4
>>>

>>> minutes = 105


>>> minutes / 60
1.75
>>> minutes = 105
>>> hours = minutes // 60
>>> hours
1
>>> remainder = minutes % 60
>>> remainder
45

Variable names
>>> 76trombones = 'big parade'
SyntaxError: invalid syntax
>>> more@ = 1000000
SyntaxError: invalid syntax
>>> class = 'Advanced Theoretical Zymurgy'
SyntaxError: Invalid syntax

Python 3 keywords
False
None
True
and del
as
elif
assert
break

class
continue
def from
global
if
else
except

finally is
return
for lambda
try
nonlocal while
not with
or
yield
import
pass
in
raise

You might also like