name="Klinsman"
i=0
while i<=7:
print "%c" % (name[i]), #method of printing without line feed
i+=1
print "\n"
name="Klinsman "
i=0
while name[i]!=' ':
print "%c" % (name[i]),
i+=1
print "\n"
name="Klinsman "
ptr=[]
ptr=name #store base address of string
i=0
while name[i]!=' ':
print "%c" % (ptr[i]),
i+=1
print "\n"
name="Klinsman"
print "%s" % (name)
print "Enter your name"
name=raw_input()
print "Hello %s!\n" % (name)
print "Enter your full name:"
name=raw_input()
print "Hello!"
print name
str1="Hello"
s="Good Morning"
str2=str1 #No error in Python since all variables are by default pointers
q=s
str1="Hello"
p="Hello"
str1="Bye" #No error in python
p="Bye"
arr="Bamboozled"
len1=len(arr) #return length of string
len2=len("Humpty Dumpty")
print "string=%s length=%d\n" % (arr,len1)
print "string=%s length=%d\n" % ("Humpty Dumpty",len2)
def xstrlen(s):
length=0
for item in s:
if s!="\0":
length+=1
return length
arr="Bamboozled"
len1=xstrlen(arr)
len2=xstrlen("Humpty Dumpty")
print "string=%s length=%d\n" % (arr,len1)
print "string=%s length=%d\n" % ("Humpty dumpty",len2)
import copy
source="Sayonara"
target=copy.copy(source) #copy string
print "source string=%s\n" % (source)
print "target string=%s\n" % (target)
def xstrcpy(t,s):
t="\0"
for item in s:
t=t+str(item)
return t
source="Sayonara"
target=[]
target=xstrcpy(target,source)
print "source string=%s\n" % (source)
print "target string=%s\n" % (target)
pi=3.14
print "Enter radius of circle"
r=eval(raw_input())
a=pi*r*r
print "Area of circle=%f\n" % (a)
source="Folks!"
target="Hello"
target=target+source
print "source string=%s\n" % (source)
print "target string=%s\n" % (target)
string1="Jerry"
string2="Ferry"
i=cmp(string1,"Jerry")
j=cmp(string1,string2)
k=cmp(string1,"Jerry boy")
print "%d %d %d\n" % (i,j,k)
def FOUND():
return 1
def NOTFOUND():
return 0
masterlist=["akshay","parag","raman","srinivas","gopal","rajesh"]
print "Enter your name"
yourname=raw_input()
flag=NOTFOUND()
for i in range(0,6,1):
a=cmp(masterlist[i],yourname)
if a==0:
print "Welcome,you can enter the palace\n"
flag=FOUND()
break
if flag==NOTFOUND():
print "Sorry,you are a trespasser\n"
names=["akshay","parag","raman","srinivas","gopal","rajesh"]
names = map(bytearray, names)
print "Original:%s %s\n" % (names[2],names[3])
s = sorted((names[2], names[3]), key=len)
for i in range(len(s[1])):
try:
t=s[0][i]
s[0][i]=s[1][i]
s[1][i]=t
except IndexError:
for _ in range(i, len(s[1])):
#remove the items from the longer string to and append them to the shorter one.
s[0].append(s[1].pop(i))
print "New:%s %s\n" % (names[2],names[3])
names=["akshay","parag","raman","srinivas","gopal","rajesh"]
print "Original:%s %s\n" % (names[2],names[3])
t=names[2]
names[2]=names[3]
names[3]=t
print "New:%s %s\n" % (names[2],names[3])
names=[]
for i in range(6):
names.append("\0")
for i in range(0,6,1):
print "Enter name"
names[i]=raw_input()
names=[]
for i in range(0,6):
names.append('\0')
for i in range(0,6,1):
print "Enter name"
n=raw_input()
length=len(n)
import copy
p=copy.copy(n)
names[i]=p
for i in range(0,6,1):
print "%s\n" % (names[i])