import sys
number = 10;
print "number's address: ", id(number)
print "number's value: ", number
pnumber = id(number)
print "pnumber's address: ", id(pnumber)
print "pnumber's size: %d bytes" %(sys.getsizeof(pnumber))
print "pnumber's value: ", pnumber
print "value pointed to: ", number
num1 = 0
num2 = 0
pnum = None
pnum = id(num1)
num1 = 2
num2 += 1
num2 += num1
pnum = id(num2)
num2 += 1
print "num1 = %d num2 = %d pnum = %d pnum + num2 = %d" %(num1, num2, pnum, pnum + num2)
print "Input an integer: ",
value = int(raw_input())
print "You entered: ", value
multiple = ['M', 'y','s','t', 'r', 'i', 'n', 'g']
p = id(multiple[0])
print "The address of the first array element : ", p
p = id(multiple)
print "The address obtained from the array name: ", p
multiple = "a string"
p = multiple
for i in range(len(multiple)):
print "multiple[%d] = %c *(p+%d) = %c id(multiple[%d]) = %d p+%d = %d " %(i, multiple[i], i, p[i], i, id(multiple[i]), i, id(p[i]))
import sys
multiple = [15, 25, 35, 45]
p = multiple
for i in range(sys.getsizeof(multiple)/sys.getsizeof(multiple[0])):
print "address p+%d (id(multiple[%d])): %d *(p+%d) value: %d" %( i, i, id(p[i]), i, p[i])
print "Type integer occupies: %d bytes" %sys.getsizeof(int())
board = [['1','2','3'],
['4','5','6'],
['7','8','9']]
print "address of board : ", id(board)
print "address of board[0][0] : ", id(board[0][0])
print "value of board[0]: ", board[0]
board = [['1','2','3'],
['4','5','6'],
['7','8','9']]
print "value of board[0][0] : %c" % (board[0][0])
print "value of board[0]: ", board[0][0]
print "value of **board: ", board[0][0]
board = [['1','2','3'],
['4','5','6'],
['7','8','9']]
for i in range(3):
for j in range(3):
print " board: ", board[i][j]
board = [['1','2','3'],
['4','5','6'],
['7','8','9']]
for i in range(3):
for j in range(3):
print " board: ", board[i][j]
size = [['6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', '7'],
['1', '5', '3', '7', ' ', '1', '1', '3', '1', '5', '3', '7'],
['2', '8', '4', '8', ' ', '8', '4', '8', '2', '8', '4', '8']]
headsize = [164, 166, 169, 172, 175, 178, 181, 184, 188, 191, 194, 197]
hat_found = False
print "Enter the circumference of your head above your eyebrows in inches as a decimal value: ",
cranium = float(raw_input())
your_head = int(8.0*cranium)
i = 0
if(your_head == headsize[i]):
hat_found = True
else:
for i in range(1, len(headsize)):
if(your_head > headsize[i - 1] and your_head <= headsize[i]):
hat_found = True
break
if(hat_found):
print "Your hat size is %c %c%c%c" %(size[0][i], size[1][i], ' ' if (size[1][i]==' ') else '/', size[2][i])
else:
if(your_head < headsize[0]):
print "You are the proverbial pinhead. No hat for you I'm afraid."
else:
print "You, in technical parlance, are a fathead, No hat for you, I'm afraid."
pPrimes = []
found = False
print "How many primes would you like - you'll get at least 4? ",
total = int(raw_input())
total = 4 if total < 4 else total
pPrimes.append(2) # First prime
pPrimes.append(3) # Second prime
pPrimes.append(5) # Third prime
count = 3
trial = 5
while(count < total):
trial += 2
for i in range(1, count):
if((trial % pPrimes[i]) == 0):
found = False
break
else:
found = True
if(found):
pPrimes.append(trial)
count += 1
for i in range(total):
print "\t", pPrimes[i],
if(not((i+1) % 5)):
print ""
import sys
print "Enter text on an arbitrary number of lines (go on typing hit enter to terminate): "
print "Should be less than 10000 characters: "
text = raw_input()
if len(text) > 10000:
print "Maximum length exceeded, terminating..."
sys.exit()
distinct_words = []
word_occurrance = []
list_text = text.split(" ")
for word in list_text:
if not word in distinct_words:
distinct_words.append(word)
word_occurrance.append(0)
for i in range(len(list_text)):
if list_text[i] in distinct_words:
index = distinct_words.index(list_text[i])
word_occurrance[index] += 1
for i in range(len(distinct_words)):
if(i % 5 == 0):
print "\n"
print distinct_words[i], "\t ", word_occurrance[i],
print "Enter strings to be sorted, separated by '.' Press Enter to end: "
text = raw_input()
dot_separated = text.split('.')
text_sorted = sorted(dot_separated)
for str in text_sorted:
print str
print "To use this calculator, enter any expression with or without spaces."
print "An expression may include the operators"
print " +, -, *, /, %, or **(raise to a power)."
print "Use = at the beginning of a line to operate on "
print "the result of the previous calculation."
print "Enter quit to stop the calculator."
result = 0
while True:
e = raw_input()
if e == 'quit':
break
else:
try:
result = eval(str(result) + e)
print "= ",result
except ZeroDivisionError:
print "Division by zero"