Pages

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Wednesday, 23 March 2016

Alphabet D Of Asterick '*'

# To print Alphabet D of Asterick '*'
# Set your font type As Courier New


n=int(raw_input("Enter a Number : "))
m=n
n=(n-1)/2
for i in range(n) :
    print "*",
print
for i in range(m-2) :
    print "*",
    for i in range(n-1) :
        print " ",
    print "*"
for i in range(n) :
    print "*",
print

OUTPUT
Enter a Number : 9
* * * *
*       *
*       *
*       *
*       *
*       *
*       *
*       *
* * * *

Sunday, 20 March 2016

Alphabet C Of Asterick '*'

# To print Alphabet C of Asterick '*'
# Set your font type As Courier New

n=int(raw_input("Enter a Number : "))
n=(n-1)/2
print " ",
for i in range(n) :
    print "*",
print
for i in range(2*n-1) :
    print "*"
print " ",
for i in range(n) :
    print "*",
print

OUTPUT
Enter a Number : 9
  * * * *
*
*
*
*
*
*
*
  * * * *

Thursday, 10 March 2016

Pallindrome String

# WAP to check if a string is pallindrome or not
# Set Your Font as Courier New

z=raw_input("Enter a string: ")
z.lower()
for i in range(-len(z),0) :
x=x+z[i]
if x==z :
print "Given String is Pallindrome"
else :
print "Given String is not a Pallindrome"

Output 1
Enter a string: aIbohPhoBiA
Given String is Pallindrome

Output 2
Enter a string: palindrome
Given String is not a Pallindrome

Sunday, 7 February 2016

Stack Operations in Python

#program for stack operations
def isempty(stk) :
    if len(stk)==0 :
        return True
    else :
        return False
def PUSH(stk) :
    x=[]
    n=raw_input("Enter Your Name : ")
    no=int(raw_input("Enter Your Number"))
    x.append(n)
    x.append(no)
    stk.append(x)       #x Stores the data in list [Name,Number]
    return stk
def POP(stk) :
    if isempty(stk) :
        print "Empty Stack"
    else :
        x=stk.pop()
        return x
def DISPLAY(stk) :
    y=len(stk)
    z=y
    for i in range(y) :
        if i==0 :
            x=POP(stk)
            print "Item number",z,"is",x,"<----Top"
            z=z-1
        elif i==y-1 :
            x=POP(stk)
            print "Item number",z,"is",x,"<----Bottom"
            z=z-1
        elif i!=0 :
            x=POP(stk)
            print "Item number",z,"is",x
            z=z-1
        no=x.pop()
        n=x.pop()
        print "Name : ",n
        print "Number : ",no
stk=[['Anurag', 9958220446],['Ayush', 8138987125],['Jagrat', 9956288854]]
while True :
    print """Choose from the following menu : -
1) PUSH
2) POP
3) DISPLAY
4) EXIT"""
    ch=int(raw_input("Enter Your Choice : "))
    if ch==1 :
        PUSH(stk)
    elif ch==2 :
        if isempty(stk) :
            x=None
            print "Empty Stack"
        else :
            x=POP(stk)
            print x,"is the popped item."   #To show the popped data
            no=x.pop()
            n=x.pop()
            print "Name : ",n
            print "Number : ",no
    elif ch==3 :
        DISPLAY(stk)
    else :
        break



Tuesday, 26 January 2016

How to make a program on a topic?

Wondered how easy can a program becomes when you think of the program
to be giving output in your mind.

Programming in python is one of the interesting and easiest thing I have ever
encountered in my life. So a program can be made with high quality and less quantity.

1. First write an output model of your program.

2. Then think of what could be the possible way for it to be done.

3. Then make use if your programming instinct to make your program on the run.

4. If needed you can refer to a book for the functions and statements needed to do what
    you thought earlier in step 2.

5. Finally saving all see the output of your hard work in the output window.

Thank You!

You can follow me on twitter @AnuragShukla47