>>> L = [1, 2, 3]
>>> L.append(4); L
[1, 2, 3, 4]
>>>
>>>

# interact.py ###################################

"""
while True:
    inp = raw_input('Age=>')
    if inp == 'stop':
        break
    elif not inp.isdigit():
        print 'Bad!' * 8
    else:
        print float(inp) ** 2
print 'bye'
"""


while True:
    inp = raw_input('Age=>')
    if inp == 'stop': break
    try:
        print float(inp) ** 2
    except:
        print 'Bad!' * 8
print 'bye'

##################################################

>>> x = raw_input('input=')
input=spam
>>> x
'spam'
>>> '42' + 1

Traceback (most recent call last):
  File "<pyshell#393>", line 1, in <module>
    '42' + 1
TypeError: cannot concatenate 'str' and 'int' objects
>>> 
>>> int('42')
42
>>> str(1)
'1'
>>> int('42') + 1
43
>>> '42' + str(1)
'421'
>>>
>>> x = raw_input('input=')
input=99
>>> x
'99'
>>> x = input('input=')
input=99
>>> x
99
>>> x = input('input=')
input={'a':1, [1, 2, 3]}
KeyboardInterrupt
>>> 
>>> {'a':1, 'b': [1, 2, 3]}
{'a': 1, 'b': [1, 2, 3]}
>>> ================================ RESTART ================================
>>> 
Age=>40
1600
Age=>50
2500
Age=>60
3600
Age=>stop
bye
>>> ================================ RESTART ================================
>>> 
Age=>6
36
Age=>spam

Traceback (most recent call last):
  File "C:/pyclass/interact.py", line 4, in <module>
    print int(inp) ** 2
ValueError: invalid literal for int() with base 10: 'spam'
>>> 
>>> s = '123'
>>> s.isdigit()
True
>>> ================================ RESTART ================================
>>> 
Age=>8
64
Age=>spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age=>7
49
Age=>stop
bye
>>> 
>>> float(12.5)
12.5
>>> 
>>> float('12.5')
12.5
>>> 
>>> float('12.5E-100')
1.25e-99
>>> ================================ RESTART ================================
>>> 
Age=>8
64.0
Age=>20.5
420.25
Age=>1.09e-99
1.1881e-198
Age=>spam
Bad!Bad!Bad!Bad!Bad!Bad!Bad!Bad!
Age=>9
81.0
Age=>stop
bye
>>> 
>>>
>>> 
>>> X = Y = 0
>>> X = X + 1
>>> X
1
>>> Y
0
>>> 
>>> 
>>> X = Y = []
>>> X.append(1)
>>> X
[1]
>>> Y
[1]
>>> 
>>> X, Y = [], []
>>> X.append(1)
>>> X
[1]
>>> Y
[]
>>> 
>>> X = Y = 0
>>> X += 1
>>> 
>>> 
>>> X++   --X   
KeyboardInterrupt
>>> 
>>> 
>>> 
>>> import M
KeyboardInterrupt
>>> 
>>> 
>>> L = [1, 2, 3]
>>> L.append(4)
>>> L
[1, 2, 3, 4]
>>> 
>>> L = L.append(5)
>>> print L
None
>>> 
>>> D = {'a': 1, 'b': 2, 'c': 3}
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> Ks = D.keys()
>>> Ks.sort()
>>> Ks
['a', 'b', 'c']
>>> 
>>> for key in D.keys().sort():
	print key, '=', D[key]


Traceback (most recent call last):
  File "<pyshell#459>", line 1, in <module>
    for key in D.keys().sort():
TypeError: 'NoneType' object is not iterable
>>> 
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> Ks = D.keys()
>>> Ks.sort()
>>> for key in Ks:
	print key, '=', D[key]

	
a = 1
b = 2
c = 3
>>> 
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>>
>>> for key in sorted(D):
	print key, '=', D[key]

	
a = 1
b = 2
c = 3
>>> help(list.append)
Help on method_descriptor:

append(...)
    L.append(object) -- append object to end

>>> dir(list)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> 
>>>
>>> import ds
>>> print ds.__doc__

Module documentation
Words Go Here

>>> print ds.square.__doc__

    function documentation
    can we have your liver then?
    
>>> help(ds)
Help on module ds:

NAME
    ds

FILE
    c:\pyclass\ds.py

DESCRIPTION
    Module documentation
    Words Go Here

FUNCTIONS
    square(x)
        function documentation
        can we have your liver then?

DATA
    spam = 40


>>>
>>> F = open('script1.py')
>>> F.readline()
'print 2 ** 640\n'
>>> F.readline()
'import sys\n'
>>> F.readline()
'pint sys.platform\n'
>>> F.readline()
"x = 'spam' \n"
>>> F.readline()
"print x + 'NI!'\n"
>>> F.readline()
''
>>> 
>>> F = open('script1.py')
>>> F.next()
'print 2 ** 640\n'
>>> F.next()
'import sys\n'
>>> F.next()
'pint sys.platform\n'
>>> F.next()
"x = 'spam' \n"
>>> F.next()
"print x + 'NI!'\n"
>>> F.next()

Traceback (most recent call last):
  File "<pyshell#492>", line 1, in <module>
    F.next()
StopIteration
>>> 
>>> for line in open('script1.py'):
	print line.upper(),

	
PRINT 2 ** 640
IMPORT SYS
PINT SYS.PLATFORM
X = 'SPAM' 
PRINT X + 'NI!'
>>> 
>>> F = open('script1.py')
>>> while True:
	line = F.readline()
	if not line: break
	print line.upper(),

	
PRINT 2 ** 640
IMPORT SYS
PINT SYS.PLATFORM
X = 'SPAM' 
PRINT X + 'NI!'
>>> 
>>> for line in open('script1.py'):
	print line.upper(),

	
PRINT 2 ** 640
IMPORT SYS
PINT SYS.PLATFORM
X = 'SPAM' 
PRINT X + 'NI!'
>>> 
>>> for line in open('script1.py').readlines():
	print line.upper(),

	
PRINT 2 ** 640
IMPORT SYS
PINT SYS.PLATFORM
X = 'SPAM' 
PRINT X + 'NI!'
>>> 
>>>
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> D.next()

Traceback (most recent call last):
  File "<pyshell#515>", line 1, in <module>
    D.next()
AttributeError: 'dict' object has no attribute 'next'
>>> 
>>> I = iter(D)
>>> I.next()
'a'
>>> I.next()
'c'
>>> I.next()
'b'
>>> I.next()

Traceback (most recent call last):
  File "<pyshell#521>", line 1, in <module>
    I.next()
StopIteration
>>> 
>>> for key in D:
	print key, D[key]

	
a 1
c 3
b 2
>>> 
>>> ord('s')
115
>>> ord('spam')

Traceback (most recent call last):
  File "<pyshell#528>", line 1, in <module>
    ord('spam')
TypeError: ord() expected a character, but string of length 4 found
>>> 
>>>
>>> L = [1, 2, 3, 4, 5]
>>> for x in L:
	x += 10

	
>>> L
[1, 2, 3, 4, 5]
>>> x
15
>>> L
[1, 2, 3, 4, 5]
>>>
>>> for i in range(len(L)):
	L[i] += 10

	
>>> L
[11, 12, 13, 14, 15]
>>> 
>>> M = [x + 10 for x in L]
>>> M
[21, 22, 23, 24, 25]
>>> 
>>> L
[11, 12, 13, 14, 15]
>>> 
>>> L = [x + 10 for x in L]
>>> L
[21, 22, 23, 24, 25]
>>> 
>>> res = []
>>> for x in L:
	res.append(x + 10)

	
>>> res
[31, 32, 33, 34, 35]
>>> 
>>> res = []
>>> for x in 'spam':
	res.append(ord(x))

>>> res
[115, 112, 97, 109]
>>> 
>>> [ord(x) for x in 'spam']
[115, 112, 97, 109]
>>> 
>>> map(ord, 'spam')
[115, 112, 97, 109]
>>> 
>>> L = [x + 10 for x in L]
>>> L
[31, 32, 33, 34, 35]
>>> 
>>> def f(X): return X + 10

>>> map(f, L)
[41, 42, 43, 44, 45]
>>> 
>>>
>>> F = open('script1.py')
>>> lines = F.readlines()
>>> lines
['print 2 ** 640\n', 'import sys\n', 'pint sys.platform\n', "x = 'spam' \n", "print x + 'NI!'\n"]
>>> 
>>> lines = [line.rstrip() for line in lines]
>>> lines
['print 2 ** 640', 'import sys', 'pint sys.platform', "x = 'spam'", "print x + 'NI!'"]
>>> 
>>> lines = [line.rstrip() for line in open('script1.py')]
>>> lines
['print 2 ** 640', 'import sys', 'pint sys.platform', "x = 'spam'", "print x + 'NI!'"]
>>> 
>>> lines = [line.rstrip() for line in open('script1.py') if line[0] == 'i']
>>> lines
['import sys']
>>> 
>>> res = []
>>> for line in open('script1.py'):
	if line[0] == 'i':
		res.append(line.rstrip())

>>> res
['import sys']
>>> 
>>> [x + y for x in 'abc' for y in 'xyz']
['ax', 'ay', 'az', 'bx', 'by', 'bz', 'cx', 'cy', 'cz']
>>> 
>>> res = []
>>> for x in 'abc':
	for y in 'xyz':
		res.append(x + y)
		
>>> res
['ax', 'ay', 'az', 'bx', 'by', 'bz', 'cx', 'cy', 'cz']
>>> 
>>> [x ** 2 for x in range(5)]
[0, 1, 4, 9, 16]
>>> 
>>> {x ** 2 for x in range(5)}
set([0, 1, 4, 16, 9])
>>> 
>>> {x: x ** 2 for x in range(5)}
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}
>>> 
>>> (x ** 2 for x in range(5))
<generator object <genexpr> at 0x000000000274D480>
>>> 
>>> g = (x ** 2 for x in range(5))
>>> g.next()
0
>>> g.next()
1
>>> 
>>> 
>>> import __builtin__
>>> 
>>> dir(__builtin__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>> 
>>> open = 42
>>> open
42
>>> 
>>> del open
>>> open
<built-in function open>
>>>
>>> file = open(....)  
KeyboardInterrupt
>>> 
>>> True = False
>>> True
False
>>> __builtin__.True = False   
KeyboardInterrupt
>>> 
>>> 
>>> 
>>> def maker(N):
	def action(X):
		return X ** N
	return action

>>> F = maker(3)
>>> F
<function action at 0x0000000002820908>
>>> 
>>> F(2)
8
>>> G = maker(10)
>>> G
<function action at 0x0000000002820AC8>
>>> G(2)
1024
>>> F(2)
8
>>>
>>> D = {'a': 1, 'b': 2, 'c': 3}
>>> 
>>> D = dict(a=1, b=2, c=3)
>>> D
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> def altdict(**args): return args

>>> altdict(a=1, b=2, c=3)
{'a': 1, 'c': 3, 'b': 2}
>>> 
>>> min(1, 3, 2, 4, 1, 5)
1
>>> 
>>> def mymin(*args):
	res = args[0]
	for x in args[1:]:
		if x < res:
			res = x
	return res

>>> mymin(1, 3, 2, 4, 1, 5)
1
>>> mymin('aa', 'bb', 'aa', 'cc')
'aa'
>>> ================================ RESTART ================================
>>> 

# actiontable.py ##############################

actions = [
    lambda x: x ** 2,
    lambda x: x ** 3,
    lambda x: x ** 4]


print actions[0](3)
print actions[1](3)

for action in actions:
    print action(4)


#-----------------------------

def f1(x): return x ** 2
def f2(x): return x ** 3
def f3(x): return x ** 4

actions = [f1, f2, f3]

print actions[0](3)
print actions[1](3)

for action in actions:
    print action(4)

##############################################

9
27
16
64
256
>>> ================================ RESTART ================================
>>> 
9
27
16
64
256
9
27
16
64
256
>>> 
>>> import script1
4562440617622195218641171605700291324893228507248559930579192517899275167208677386505912811317371399778642309573594407310688704721375437998252661319722214188251994674360264950082874192246603776
win32
spamNI!
>>> 
>>> import script1
>>> import script1
>>> import script1
>>> 
>>> reload(script1)
4562440617622195218641171605700291324893228507248559930579192517899275167208677386505912811317371399778642309573594407310688704721375437998252661319722214188251994674360264950082874192246603776
win32
spamNI!
<module 'script1' from 'C:/pyclass\script1.pyc'>
>>> 
>>> reload(script1)
4562440617622195218641171605700291324893228507248559930579192517899275167208677386505912811317371399778642309573594407310688704721375437998252661319722214188251994674360264950082874192246603776
win32
spamNI!
<module 'script1' from 'C:/pyclass\script1.pyc'>
>>> 
>>> 
>>> fname = 'script1.py'
>>> 
>>> len(open(fname).read())
73
>>> len(open(fname).readlines())
5
>>> 
>>> tot = 0
>>> for line in open(fname): tot += len(line)

>>> tot
73
>>> 
>>> tot = 0
>>> for line in open(fname): tot += 1

>>> tot
5
>>> 
>>> def countChars(fname):
	return len(open(fname).read())

>>> countChars(fname)
73
>>> dir(file)
['__class__', '__delattr__', '__doc__', '__enter__', '__exit__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'close', 'closed', 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'mode', 'name', 'newlines', 'next', 'read', 'readinto', 'readline', 'readlines', 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines', 'xreadlines']
>>> help(file.read)
Help on method_descriptor:

read(...)
    read([size]) -> read at most size bytes, returned as a string.
    
    If the size argument is negative or omitted, read until EOF is reached.
    Notice that when in non-blocking mode, less data than what was requested
    may be returned, even if no size parameter was given.

>>> 