Thursday, November 29, 2012

PYTHON REFERENCES

    1. Online Python Tutor : It is a free educational tool that helps students overcome a fundamental barrier to learning programming: understanding what happens as the computer executes each line of a program's source code. Using this tool, a teacher or student can write a Python program directly in the web browser and visualize what the computer is doing step-by-step as it executes the program.
    2. life is short - you need Python!: A blog on Python with tutorials, code, programs, tips and tricks, how-to, book-list, crawler / spider help, data structure and algorithm implementation and many more ... maintained by Tamim Shahriar Subeen, one of the best IT professional in Bangladesh.
    3. Python for fun - advanced python codes: This collection is a presentation of several small Python programs. They are aimed at intermediate programmers; people who have studied Python and are fairly comfortable with basic recursion and object oriented techniques. Each program is very short, never more than a couple of pages and accompanied with a write-up.
    4. site aims to be both a library of educational materials using Python to teach computer programming, and a virtual meeting place for teachers and students engaged in learning and teaching using Python.  Happy computing!

Monday, November 26, 2012

Turtle

Turtle is a Python module to draw pictures.
import turtle # allows us to use the turtles library
wn = turtle.Screen() # creates a graphics window
alex = turtle.Turtle() # create a turtle named alex
alex.forward(150) # tell alex to move forward by 150 units
alex.left(90) # turn by 90 degrees
alex.forward(75) # complete the second side of a rectangle
wn.exitonclick()

Friday, November 23, 2012

Sending SMS via USB Connected Cell Phone with Python

import serial
import time
class SMSsender:
    def __init__(self):
        self.destination = ""
        self.msg = ""

    def setRecipient(self, dest):
        self.destination = dest

    def setContent(self, message):
        self.msg = message

    def connectPhone(self):
        #replace '/dev/ttyACM0' with your device name
        #replace 460800 with a suitable baud-rate of your phone 
        self.ser = serial.Serial('/dev/ttyACM0', 460800, timeout=2)
        time.sleep(1)

    def sendMessage(self):
        self.ser.write('ATZ\r')
        time.sleep(1)
        self.ser.write('AT+CMGF=1\r')
        time.sleep(1)
        self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''')
        time.sleep(1)
        self.ser.write(self.content + "\r")
        time.sleep(1)
        self.ser.write(chr(26))
        time.sleep(1)

    def disconnectPhone(self):
        self.ser.close()
To send sms use this follow the code below:
sms = SMSsender()
sms.setRecipient('+8801*********')
sms.setContent('Write your message here')
sms.connectPhone()
sms.sendMessage()
sms.disconnectPhone()
You may also try this link(I've not tested yet): sms-over-3g-and-bluetooth-from-python
Source: linux-101.org

Tuesday, November 6, 2012

Make them all glow, can you?


Instructions:
 Click on orbs arranged in a grid to make them all glow. Clicking on an orb 
changes its state from unlit to lit or lit to unlit along with the 
neighboring orbs. Turn on all the orbs to pass a level with as few moves 
as you can. There are 9 levels, each with more orbs than the previous one.
Two difficulty modes. In the easy mode, all orbs are unlit in the beginning 
and in the hard mode, some orbs are already lit to make things difficult 
for the player.
Author:
MUKTO SOFTWARE LTD.

Monday, November 5, 2012

Python - Coding with fun

How to reverse a string?

s = 'abcdef'
s = s[::-1]
print s 
Explanation: "::" is known as stride notation
s[::2]
s[::-2]
Returns "ace" and "fdb" respectively.

How to read from console in Python?
name = raw_input()

Want to read an integer?
num = raw_input()
num = int(num) # raw_input returns string, so convert it to integer

Swap values in python:
a, b = b, a

My motivation to learn python is: life is short - you need Python