A workshop on

Game Development using Python

Organized by CSEA

Press 'F' for Fullscreen
Press Space to navigate the presentation

Creating your first Python file

Open gedit and type

print "hello world"

Save the file as filename.py

Running your first Python file

In your terminal, type


user:~$ python filename.py
					

Few examples of Python statements


print "python is cool"
a = input()
b = 5
c = "hello"
d = a + b
b = b + 1 
a += 1
print d, b
                    

Try them!! Take around 7 and a half minutes :)

Some powerful statements...

Conditional Statements


if <condition 1>:
    statement 1
    statement 2
    ....
                    

Pay special attention to indentation and the colon (:) symbol

Some powerful statements...

Conditional Statements

Enhancing the if-conditions


if <condition 1>:
    statement 1
    statement 2
    ....
elif <condition 2>:
    statement 3
    statement 4
else:
    statement 5
    ....
                    

Pay special attention to indentation and the colon (:) symbol

Let's try something

I give you a point in the graph.

You tell me which quadrant it lies in. Can you?


Sample Input (Take x as input first then y as input): 
-2
3

Sample Output (Print the quadrant number):
2
                    

Don't go to the next slide before you try this question !!

Let's see the solution

Hope you tried it yourself first :)


x = input()
y = input()
if x > 0 and y > 0:
    print 1
elif x < 0 and y > 0:
    print 2
elif x < 0 and y < 0:
    print 3
elif x > 0 and y < 0:
    print 4
else:
    print "Not in any quadrant"
                    

Dont forget the indentation and colon (:) where required

Some powerful statements...

Looping statements


while <condition>:
    statement 1
    statement 2
    ....
                    

Pay special attention to indentation and the colon (:) symbol

Let's try something again!

Give me even numbers from 1 to 100


Sample Input: 
{no input}

Sample Output:
2
4
6
8
...
...
98
100
                    

We will try this for another 7 and a half minutes :P

You need to submit a Physics Assignment. What steps will you take to complete it?

Functions

Functions help us stand on the shoulders of giants!


import math

pi = math.pi
a = math.sin(pi/2)
print a
                    

List and tuples

This is a list. It is bound by square brackets []


[1, 2, "hello", [3, 4]]
                    

This is a tuple. It is bound by round brackets ()


(1, 2, "hello", [3, 4])
                    

Once created, contents of tuples cannot be changed. For a list, we can modify.

One last thing before you become a Ninja Python Programmer

Revisitng loops

for loop


number = input()
ls = [1, 2, 3, 4]
for multiples in ls:
    print number, "x", multiples, "=", multiples * number 
                    

Pay special attention to indentation and the colon (:)

TAKE A BREAK!

Let's head over to building the game.... Click here