Find us on Google+ Kill the code

Saturday, 1 September 2012

Loops in PYTHON

>>> x=0
>>> i=0
>>> a=['a','b','c','d']
>>> for x in a:
    print(x)

   
a
b
c
d






>>> while i < 10:
    print(i)
    i+=1

   
0
1
2
3
4
5
6
7
8
9

Friday, 31 August 2012

Start PYTHON Today...

Input & Output:


>>> name=input("Enter your name  ")
Enter your name  nisarg

>>> interest=input("What is your interest  ")
What is your interest  programming

>>> define=input("How do you define your self   ")
How do you define your self   codekiller

Value of the variable defined....

>>> print(name)
nisarg

>>> print(interest)
programming

>>> print(define)
codekiller

Thursday, 30 August 2012

Guess the Number game in Python

Below is the program for Guess The Number Game.
Run the program and then choose the number,thereby it will guess it. 
 


 
import random

guesses_made = 0

name = raw_input('Hello! What is your name?\n')

number = random.randint(1, 20)
print 'Well, {0}, I am thinking of a number between 1 and 20.'.format(name)

while guesses_made < 6:

    guess = int(raw_input('Take a guess: '))

    guesses_made += 1

    if guess < number:
        print 'Your guess is too low.'

    if guess > number:
        print 'Your guess is too high.'

    if guess == number:
        break

if guess == number:
    print 'Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made)
else:
    print 'Nope. The number I was thinking of was {0}'.format(number)