samiuljahan's blog

there's always room for improvement

Python Primer

leave a comment »

Recently I’ve started to play with Python. I’ve heard a lot about this language before.  Recently I’ve just completed my  ‘Hello World’ program  🙂

You can get Python from here. I use python’s interactive shell as well as PyDev plugin for Eclipse to write codes

#This is a comment
#version 3.0
print("Hello World!"); #semicolon is not required but I use this
  • Commenting code
#This is a comment
  • Assigning values
x = 5 #5 is assigned to x
print (x) #prints 5
print (type(x)) # outputs <class 'int'>
x, y = 0, 1
x, y = y, x
print(x,y) # prints 1, 0
  • Conditions
#traditional conditions
x , y = 10, 20
    if x < y :
       print ('X is less than Y') # prints 'X is less than Y'

#conditional expressions
x, y = 0, 1
z = "less than" if x < y else "not less than"
print (z) #prints 'less than'
  • Writing a function
#defining a function
def myFunc():
    print('This is a function in python')
#invoking the function
myFunc() # prints 'This is a function in python'
  • Writing a class
class Language:
    def __init__(self, name = 'Python'):      #constructor
        self.name = name
    def showName(self):
        return self.name
scripting = Language()                       #an instance of the Language class
print(scripting.showName())                  #as you've guessed :), it prints 'Python'

procedural = Language('C')                     #another instance of the Language class
print(procedural.showName())                #now it prints 'C' 🙂
  • Getting Input from the User
hawkingsFound = input('Enter what hawkings found lately? :)') #prompts the user 'Enter what hawkings found lately? :)' , user enters 'girls are mysterious'
print(hawkingsFound) # it prints 'girls are mysterious' 🙂
Advertisements

Written by সামিউল(samiul)

January 7, 2012 at 4:42 pm

How to calculate the time required for a block of code in C/C++?

leave a comment »

Here are a small code snippets with which you can calculate the execution time of a certain block of codes in C/C++.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
clock_t startm, stopm;
#define START if ( (startm = clock()) == -1) {printf("Error calling clock");exit(1);}
#define STOP if ( (stopm = clock()) == -1) {printf("Error calling clock");exit(1);}
#define PRINTTIME printf( "%6.3f seconds used by the processor.", ((double)stopm-startm)/CLOCKS_PER_SEC);
int main() {
     START;//start the timer
     //code blocks which execution time will be counted begins here
     int n;
     for(n = 0; n<=65535; n++)
     {
        printf("%d\n", n);
     }
     //code blocks which execution time will be counted ends here
     STOP;//end the timer
     PRINTTIME;//print the time
     return 0;
}

The program will print total 65536 numbers line by line and at the end it’ll print the total seconds e.g 5.109 seconds, it took to print the numbers
—–courtesy: http://kennethfinnegan.blogspot.com/2008/03/timing-events-in-c.html

Written by সামিউল(samiul)

September 10, 2011 at 6:18 pm

Basic Programming Quiz 0010

leave a comment »

Examine the code snippets given below—-

#include <stdio.h> 
int main()
{ 
    char ch;
    while((ch = getchar()) != '\0')
    putchar(ch);
    return 0;
}

What does the program display?

Look at another code snippets—-

#include <stdio.h> 
int main()
{ 
    while( putchar(getchar( )) != '\0' ) ;
    return 0;
}

Now, what does it display?
Is there any difference in program execution between these two code snippets?

Written by সামিউল(samiul)

September 10, 2011 at 11:12 am

Basic Programming Quiz 0001

leave a comment »

Examine the code snippets given below—-

#include <stdio.h> 
int main()
{ 
  int x;
  x = 10;
  if(x == 10) { 
    int x; 
    x = 99; 
    printf("Inner x: %d\n", x);
  }
  printf("Outer x: %d\n", x); 
  return 0;
}

What does the program displays?

Written by সামিউল(samiul)

September 9, 2011 at 8:47 pm

Neptune and Uranus may have oceans of diamonds!

leave a comment »

[tweetmeme]
Scientists have said that the our solar system may have oceans of diamonds.

According to ABC News, a new report has suggested that oceans of liquid diamond icebergs, could be floating on Neptune and Uranus.

The research is based on the first detailed measurements of the melting point of diamond.

Read the rest of this entry »

Written by zahidhasanaupee

January 20, 2010 at 4:23 pm

“High-Speed” Networks Are No Faster Than “Low-Speed” Networks

leave a comment »

hi speed internet
[tweetmeme]
All computer networks operate at the same speed. They send and receive data at roughly 186,000 miles per second. So,what makes those wonderful “broadband” Internet connections seem so “fast”? After all,the transmission speed is limited by the laws of physics. The answer is that computer networks use various methods to represent data on the communications link. For example,the character “U” in my name could possibly be represented by a code of eight bits (binary 0s and 1s).

Read the rest of this entry »

Written by সামিউল(samiul)

January 19, 2010 at 6:11 pm

Knowing(2009)

leave a comment »

mv5bmtmymjgymdiym15bml5banbnxkftztcwnjg3mjaymg_002
[tweetmeme]

Director:

Alex Proyas

Writers:

Ryne Douglas Pearson (screenplay) and
Juliet Snowden (screenplay)

Release Date:

20 March 2009 (USA)

Genre:

Action | Mystery | Sci-Fi | Thriller

Tagline:
Knowing is Everything…

Download Link(rmvb229mb):

Read the rest of this entry »

Written by সামিউল(samiul)

April 4, 2009 at 6:06 pm

Posted in 2009, movie

Tagged with , , , ,