n= [44] # n holds the int 44
print "int n=44; // n holds the int 44:\n";
print "\t\t n = " , n
print "\t\t &n = " , hex(id(n))
pn = n
print "int* pn=&n; // pn holds the address of n:\n";
print "\t\t n = " , n
print "\t\t &n = " , hex(id(n))
print "\t\t pn = " , hex(id(pn))
print "\t\t &pn = " , hex(id(hex(id(pn))))
print "\t\t *pn = " , pn
pn[0] = 77 # changes the value of n to 77
print "*pn = 77; // changes the value of n to 77:\n";
print "\t\t n = " , n
print "\t\t &n = " , hex(id(n))
print "\t\t pn = " , hex(id(pn))
print "\t\t &pn = " , hex(id(hex(id(pn))))
print "\t\t *pn = " , pn
q = n
print "int* q=&n; // q also holds the address of n:\n";
print "\t\t n = " , n
print "\t\t &n = " , hex(id(n))
print "\t\t pn = " , hex(id(pn))
print "\t\t &pn = " , hex(id(hex(id(pn))))
print "\t\t *pn = " , pn
print "\t\t q = " , hex(id(q))
print "\t\t &q = " , hex(id(hex(id(hex(id(pn))))))
print "\t\t *q = " , q
s = "ABCD"
for i in range(4):
print "s[" , i , "] = '" , s[i] , "'\n";
while True:
word = raw_input()
if len(word) < 2:
break
l = word.split(' ')
for i in l:
print '\t"' , i , '"'
while True:
line = raw_input()
if len(line) < 2:
break
print "\t[" , line , "]"
while True:
word = raw_input()
if len(word) < 2:
break
l = word.split(',')
for i in range(len(l)-1):
print '\t[' , l[i] , ']'
count = 0
while True:
a = raw_input()
if len(a) < 1:
break
for ch in a:
if (ch == 'e'): count+=1
print count , " e's were counted.\n"
while True:
a = raw_input()
if len(a) < 1:
break
print a.title()
a = raw_input()
l = a.split(' ')
nos = []
for i in l:
try:
i = int(i)
nos.append(i)
except:
continue
m = nos[0]
n = nos[1]
print m , " + " , n , " = " , m+n
count=0
print "Enter at most 4 names with at most 19 characters:\n";
while (True):
n = raw_input()
if len(n) < 1:
break
name.append(n)
count += 1
print "The names are:\n"
for i in range(count):
print "\t" , i , ". [" , name[i] , "]"
name = []
count=0
print "Enter at most 4 names with at most 19 characters:\n";
while (True):
n = raw_input()
if len(n) < 1:
break
name.append(n)
count += 1
print "The names are:\n"
for i in range(count):
print "\t" , i , ". [" , name[i] , "]"
name = [ "George Washington", "John Adams", "Thomas Jefferson"]
print "The names are:\n"
for i in range(3):
print "\t" , i , ". [" , name[i] , "]"
s = "ABCDEFG"
print "len(" , s , ") = " , len(s)
print "len(\"\") = " , len("")
print "Enter string: "
b = raw_input()
print "len(" , b , ") = " , len(b)
s = "The Mississippi is a long river."
print 's = "' , s , '"'
p = s.find(' ')
print "find(s, ' ') points to s[" , p , "]."
p = s.find('s')
print "find(s, 's') points to s[" , p , "]."
p = s.rfind('s')
print "reverse find(s, 's') points to s[" , p , "]."
p = s.find("is")
print "strstr(s, \"is\") points to s[" , p , "]."
p = s.find("isi")
if p== -1:
print 's.find("isi") returns NULL'
s1 = "ABCDEFG"
s2 = "XYZ"
print "Before strcpy(s1,s2):\n"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 = s2
print "After strcpy(s1,s2):\n"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 = "ABCDEFG"
s2 = "XYZ"
print "Before strcpy(s1,s2,2):\n"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 = s2[:2] + s1[2:]
print "After strcpy(s1,s2,2):\n"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 = "ABCDEFG"
s2 = "XYZ"
print "Before string concatination :\n"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 += s2
print "After string concatination :"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 = "ABCDEFG"
s2 = "XYZ"
print "Before string concatination :\n"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s1 += s2[:2]
print "After string concatination :"
print "\ts1 = [" , s1 , "], length = " , len(s1)
print "\ts2 = [" , s2 , "], length = " , len(s2)
s = "Today's date is March 12, 2000."
print "The string is: [" , s , "] \nIts tokens are: "
p = s.split(" ")
for i in p:
print "\t[" , i , "] "
print "Now the string is: [" , p[0] , "] ";
def strpbrk(s,s1):
found = []
for i in range(len(s1)):
if s1[i] in s:
index = s.find(s1[i])
found.append(index)
if found:
return min(found)
return None
s = "The Mississippi is a long river."
print 's = "' , s , '"'
p = strpbrk(s, "nopqr")
print 'strpbrk(s, "nopqr") points to s[' , p , "]."
p = strpbrk(s, "NOPQR")
if (p == None):
print 'strpbrk(s, "NOPQR") returns NULL.\n'